Snap.HTTPClient behaviour (Snap v0.13.0)

View Source

Behaviour for the HTTP client used by the Snap.Cluster.

By default, it uses the Snap.HTTPClient.Adapters.Finch for making requests.

You can configure the Cluster with your own adapter:

config :my_app, MyApp.Cluster,
  http_client_adapter: MyHTTPClientAdapter

The adapter can be configured passing a tuple:

config :my_app, MyApp.Cluster,
  http_client_adapter: {MyHTTPClientAdapter, some_config_for_adapter: "config_value"}

Summary

Callbacks

Returns a specification to start this module under the Snap supervisor tree.

Executes the request with the configured adapter.

Types

body()

@type body() :: iodata() | nil

child_spec()

@type child_spec() :: Supervisor.child_spec() | {module(), Keyword.t()} | module()

headers()

@type headers() :: [{key :: String.t(), value :: String.t()}]

method()

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

t()

@type t() :: module()

url()

@type url() :: String.t()

Callbacks

child_spec(config)

@callback child_spec(config :: Keyword.t()) :: child_spec() | :skip

Returns a specification to start this module under the Snap supervisor tree.

If the adapter doesn't need to start in the supervisor tree, you can return :skip.

request(cluster, method, url, headers, body, opts)

@callback request(
  cluster :: module(),
  method :: atom(),
  url(),
  headers(),
  body(),
  opts :: Keyword.t()
) :: {:ok, Snap.HTTPClient.Response.t()} | {:error, Snap.HTTPClient.Error.t()}

Executes the request with the configured adapter.

Functions

child_spec(config)

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