Terminus v0.1.1 Terminus.HTTP.Client View Source
A GenStage
producer module for creating streaming HTTP requests.
Each request is a GenStage process, enabling creating powerful concurrent
data flows.
Usage
# Create the connection process
iex> Terminus.HTTP.Client.connect("http://x.bitfs.network")
{:ok, pid}
# Begin a request
iex> Terminus.HTTP.Client.request(pid, "GET", path)
:ok
# Stream the result
iex> GenStage.stream([{pid, cancel: :transient}])
%Stream{}
Link to this section Summary
Functions
Manually stops the Client process, closing it's HTTP request.
Creates a new connection to a given server and returns a GenStage pid
.
Manually stops and restarts the client's current request.
Sends a request to the connected server.
Starts the client process without links (outside of a supervision tree).
Starts a client process linked to the current process.
Link to this section Types
Specs
status() :: 0 | 1 | 2
HTTP request status.
0
- Connecting1
- Connected2
- Closed
Specs
t() :: %Terminus.HTTP.Client{ conn: Mint.HTTP.t(), decoder: atom(), demand: integer(), events: list(), last_event_id: String.t(), recycle_after: integer() | nil, recycle_ref: reference(), request: Terminus.HTTP.Request.t(), request_ref: reference(), response: Terminus.HTTP.Response.t(), status: status() }
Terminus HTTP State.
Link to this section Functions
Manually stops the Client process, closing it's HTTP request.
Specs
connect(String.t(), keyword()) :: {:ok, pid()} | {:error, Exception.t()}
Creates a new connection to a given server and returns a GenStage pid
.
Options
The accepted options are:
:decoder
- Request body binary.:recycle_after
- Number of seconds after which the request should be recycled if it has recieved no events (used in EventSource connections).
Specs
recycle(pid()) :: :ok
Manually stops and restarts the client's current request.
Alternatively, this can be automated by using the :recycle_after
option
when calling connect/2
.
Specs
Sends a request to the connected server.
The function is asynchronous and returns :ok
. The GenStage pid
can be subscribed to to listen to streaming data chunks.
Options
The accepted options are:
:headers
- List of HTTP headers in tuple form.:body
- Request body binary.:token
- If provided, sets theToken
HTTP header.:last_event_id
- Used with EventSource connections. If provided, sets theLast-Event-ID
header.
Specs
start(String.t(), keyword()) :: {:ok, pid()} | {:error, Exception.t()}
Starts the client process without links (outside of a supervision tree).
Specs
start_link(String.t(), keyword()) :: {:ok, pid()} | {:error, Exception.t()}
Starts a client process linked to the current process.
This is often used to start the client process as part of a supervision tree.