View Source Snap.HTTPClient behaviour (Snap v0.9.0)

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

@type body() :: iodata() | nil
@type child_spec() :: Supervisor.child_spec() | {module(), Keyword.t()} | module()
@type headers() :: [{key :: String.t(), value :: String.t()}]
@type method() :: :get | :post | :put | :delete
@type t() :: module()
@type url() :: String.t()

Callbacks

@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.

Link to this callback

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

View Source
@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

Link to this function

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

View Source