Cables v0.1.1 Cables View Source

Asynchronous multiplexed HTTP/2 connection manager.

Create a new Cable using Cable.new_pool/2. Cables will not open a connection until the first request is recieved.

Examples

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

Link to this section Summary

Functions

If a pool is not already created for the specified uri, create one

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() :: [
  pool_timeout: integer(),
  connection_timeout: integer(),
  threshold: integer(),
  max_requests: integer(),
  max_streams: integer(),
  max_connections: integer(),
  min_connections: integer(),
  connnection_ttl: integer(),
  connection_opts: map()
]

Link to this section Functions

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

Simple DELETE request with Cables.Response

Examples

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

Simple GET request with Cables.Response

Examples

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

Simple HEAD request with Cables.Response

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

If a pool is not already created for the specified uri, create one.

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

Simple OPTIONS request with Cables.Response

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

Simple PATCH request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new_pool("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 \\ "", reply_to \\ nil) View Source
post(Cabel.t(), String.t(), [{String.t(), String.t()}], iodata(), pid()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple POST request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new_pool("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 \\ "", reply_to \\ nil) View Source
put(Cabel.t(), String.t(), [{String.t(), String.t()}], iodata(), pid()) ::
  {:ok, Cables.Response.t()} | {:error, any()}

Simple PUT request with Cables.Response

Examples

iex> {:ok, cable} = Cables.new_pool("https://nghttp2.org/")
...> {:ok, %Cables.Response{status: status}} = Cables.put(cable, "/httpbin/put", [], "hello world")
...> status
200
Link to this function request(cable, method, path, headers \\ [], body \\ "", reply_to \\ nil, module, init_args) View Source
request(
  Cabel.t(),
  http_method(),
  String.t(),
  [{String.t(), String.t()}],
  String.t(),
  pid(),
  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_pool("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.