Terminus v0.1.1 Terminus.HTTPStream View Source
A mixin module providing functions for creating streaming HTTP requests.
Examples
defmodule BitFS do
use Terminus.HTTPStream, hosts: ["x.bitfs.network"]
def load_file(path) do
case request(:fetch, "GET", path, nil) do
{:ok, data} ->
data
{:error, reason} ->
raise reason
end
end
def stream_file(path) do
case request(:stream, "GET", path, nil) do
{:ok, stream} ->
stream
{:error, reason} ->
raise reason
end
end
end
Link to this section Summary
Functions
Opens a HTTP connection and begins a request, returning the binary/0
body
of the response.
Runs the given streaming Enumerable.t/0
and executes the callback
on each element of the stream.
Normalizes the given Bitquery, automatically expanding shorthand queries.
Opens a HTTP connection and begins a request, returning the GenStage pid
of the request.
Opens a HTTP connection and begins a request, returning a streaming Enumerable.t/0
.
Link to this section Functions
Specs
fetch(String.t(), String.t(), String.t(), keyword()) :: {:ok, Enumerable.t() | pid()} | {:error, Exception.t()}
Opens a HTTP connection and begins a request, returning the binary/0
body
of the response.
Returns the result in an :ok
/ :error
tuple pair.
Specs
handle_callback(Enumerable.t(), Terminus.Streamer.callback()) :: {:ok, Enumerable.t()} | :ok | {:error, String.t()}
Runs the given streaming Enumerable.t/0
and executes the callback
on each element of the stream.
If the given callback is nil
then the stream is passed through and returned.
Specs
Normalizes the given Bitquery, automatically expanding shorthand queries.
Examples
iex> normalize_query(%{find: %{"tx.h" => "abc"}})
%{
v: 3,
q: %{
find: %{
"tx.h" => "abc"
}
}
}
Specs
request(String.t(), String.t(), String.t(), keyword()) :: {:ok, Enumerable.t() | pid()} | {:error, Exception.t()}
Opens a HTTP connection and begins a request, returning the GenStage pid
of the request.
Returns the result in an :ok
/ :error
tuple pair.
Specs
stream(String.t(), String.t(), String.t(), keyword()) :: {:ok, Enumerable.t() | pid()} | {:error, Exception.t()}
Opens a HTTP connection and begins a request, returning a streaming Enumerable.t/0
.
Returns the result in an :ok
/ :error
tuple pair.