Tornex.HTTP.Client behaviour (Tornex v0.3.0)

View Source

The behaviours of HTTP client implementations for Tornex.API.get/1.

Unless otherwise configured with config :tornex, client: AlternateClient, the default HTTP client is Tornex.HTTP.FinchClient.

The child_spec/1 callback is optional and should be configured for HTTP libraries that require a supervision tree.

Summary

Types

Body of the HTTP response.

HTTP headers for the HTTP request or response.

HTTP status code of the HTTP request.

Callbacks

Optionally get a child spec to start the HTTP client.

Perform an HTTP GET to the specified URL with the headers.

Get the name of the library and its version.

Types

body()

@type body() :: binary()

Body of the HTTP response.

headers()

@type headers() :: %{required(String.t()) => String.t()}

HTTP headers for the HTTP request or response.

response()

@type response() ::
  {:ok, status(), response_headers :: headers(), response_body :: body()}
  | {:error, term()}

status()

@type status() :: 100..599

HTTP status code of the HTTP request.

Callbacks

child_spec(opts)

(optional)
@callback child_spec(opts :: Keyword.t()) :: Supervisor.child_spec()

Optionally get a child spec to start the HTTP client.

get(url, request_headers)

@callback get(url :: String.t(), request_headers :: headers()) :: response()

Perform an HTTP GET to the specified URL with the headers.

version()

@callback version() :: String.t()

Get the name of the library and its version.