Imp.HTTP behaviour (Imp v0.5.0)

Copy Markdown View Source

Small injectable HTTP boundary used by provider clients.

A method that cannot be sent is {:error, {:http_method_not_supported, refuser, method}}, where refuser is Imp.HTTP for a method outside method/0, or the transport that cannot send it.

Summary

Types

method()

@type method() :: :get | :post | :put | :patch | :delete

Callbacks

post(t, list, iodata, keyword)

@callback post(String.t(), [{String.t(), String.t()}], iodata(), keyword()) ::
  {:ok, %{status: non_neg_integer(), body: binary(), headers: list()}}
  | {:error, term()}

request(method, t, list, iodata, keyword)

(optional)
@callback request(method(), String.t(), [{String.t(), String.t()}], iodata(), keyword()) ::
  {:ok, %{status: non_neg_integer(), body: binary(), headers: list()}}
  | {:error, term()}

stream(t, list, iodata, keyword)

(optional)
@callback stream(String.t(), [{String.t(), String.t()}], iodata(), keyword()) ::
  Enumerable.t()

Functions

post(transport, url, headers, body, opts \\ [])

request(transport, method, url, headers, body, opts \\ [])

stream(transport, url, headers, body, opts \\ [])