Cables v0.2.1 Cables View Source

Asynchronous multiplexed HTTP/2 connection manager.

Create a new Cable using Cable.new/2. Cables will immediately open min_connections specified in the profile.

Examples

{:ok, cable} = Cables.new("https://nghttp2.org/")
{:ok, %Cables.Response{status: 200}} = Cables.get(cable, "/httpbin/get")

Link to this section Summary

Functions

Create a named supervised pool to include in

Create a new pool and attach it to the global Cables supervisor

Start a request and handle it with the request_handler. Cables.Handler This gives you full control over sending and recieving stream data

Send a piece of data. Make sure to use &send_final_data/3 to send the final chunk

Send a piece of data and indicate that the request body has finished

Link to this section Types

Link to this type http_method() View Source
http_method() ::
  :get | :post | :head | :put | :patch | :options | :delete | String.t()
Link to this type profile() View Source
profile() :: [
  threshold: integer(),
  max_requests: integer(),
  max_streams: integer(),
  max_connections: integer(),
  min_connections: integer(),
  connnection_ttl: integer(),
  connection_opts: map()
]
Link to this type request_opts() View Source
request_opts() :: [
  reply_to: pid(),
  pool_timeout: integer(),
  connection_timeout: integer()
]

Link to this section Functions

Link to this function child_spec(name, uri, profile_name \\ :default) View Source
child_spec(atom(), String.t(), atom()) :: {module(), any()}

Create a named supervised pool to include in

Examples

iex> children = [ Cables.child_spec(:my_named_pool, "https://nghttp2.org/") ]
...> {:ok, _pid} = Supervisor.start_link(children, strategy: :one_for_one)
...> {:ok, %Cables.Response{status: status}} = Cables.post(:my_named_pool, "/httpbin/post", [], "hello world")
...> status
200
Link to this function delete(cable, path, headers \\ [], body \\ "", opts \\ []) View Source
delete(
  Cabel.t(),
  String.t(),
  [{String.t(), String.t()}],
  iodata(),
  request_opts()
) :: {:ok, Cables.Response.t()} | {:error, any()}

Simple DELETE request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.delete(cable, "/httpbin/delete")
...> status
200
Link to this function get(cable, path, headers \\ [], opts \\ []) View Source
get(Cabel.t(), [{String.t(), String.t()}], String.t(), request_opts()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple GET request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.get(cable, "/httpbin/get")
...> status
200

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.get(cable, "/httpbin/delay/8", [{"my-custom-header", "some_header_value"}], connection_timeout: 10_000, pool_timeout: 10_000)
...> status
200
Link to this function head(cable, path, headers \\ [], opts \\ []) View Source
head(Cabel.t(), [{String.t(), String.t()}], String.t(), request_opts()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple HEAD request with Cables.Response

Link to this function new(uri, profile_name \\ :default) View Source
new(String.t(), atom()) :: Cabel.t()

Create a new pool and attach it to the global Cables supervisor.

Link to this function options(cable, path, headers \\ [], opts \\ []) View Source
options(Cabel.t(), [{String.t(), String.t()}], String.t(), request_opts()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple OPTIONS request with Cables.Response

Link to this function patch(cable, path, headers \\ [], body \\ "", opts \\ []) View Source
patch(
  Cabel.t(),
  String.t(),
  [{String.t(), String.t()}],
  iodata(),
  request_opts()
) :: {:ok, Cables.Response.t()} | {:error, any()}

Simple PATCH request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.patch(cable, "/httpbin/patch", [], "hello world")
...> status
200
Link to this function post(cable, path, headers \\ [], body \\ "", opts \\ []) View Source
post(
  Cabel.t(),
  String.t(),
  [{String.t(), String.t()}],
  iodata(),
  request_opts()
) :: {:ok, Cables.Response.t()} | {:error, any()}

Simple POST request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.post(cable, "/httpbin/post", [], "hello world")
...> status
200
Link to this function put(cable, path, headers \\ [], body \\ "", opts \\ []) View Source
put(Cabel.t(), String.t(), [{String.t(), String.t()}], iodata(), request_opts()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple PUT request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.put(cable, "/httpbin/put", [], "hello world")
...> status
200
Link to this function request(pool, method, path, headers \\ [], body \\ "", opts \\ [], module, init_args) View Source
request(
  pid() | atom(),
  http_method(),
  String.t(),
  [{String.t(), String.t()}],
  String.t(),
  request_opts(),
  module(),
  any()
) :: t :: any()

Start a request and handle it with the request_handler. Cables.Handler This gives you full control over sending and recieving stream data.

For an example see Cables.Response.

Examples

iex> {:ok, cable} = Cables.new("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.request(cable, :get, "/httpbin/get", Cables.Response, nil)
...> status
200
Link to this function send_data(gun_pid, stream_ref, data) View Source
send_data(pid(), reference(), String.t()) :: :ok

Send a piece of data. Make sure to use &send_final_data/3 to send the final chunk.

Link to this function send_final_data(gun_pid, stream_ref, data) View Source
send_final_data(pid(), reference(), String.t()) :: :ok

Send a piece of data and indicate that the request body has finished.