View Source Assent.HTTPAdapter behaviour (Assent v0.3.0)

HTTP adapter helper module.

You can configure the which HTTP adapter Assent uses by setting the configuring:

http_adapter: Assent.HTTPAdapter.Httpc

Default options can be set by passing a list of options:

http_adapter: {Assent.HTTPAdapter.Httpc, [...]}

You can also set global application config:

config :assent, :http_adapter, Assent.HTTPAdapter.Httpc

Usage

defmodule MyApp.MyHTTPAdapter do
  @behaviour Assent.HTTPAdapter

  @impl true
  def request(method, url, body, headers, opts) do
    # ...
  end
end

Summary

Functions

Decodes request response body.

Sets a user agent header.

Types

body()

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

headers()

@type headers() :: [{binary(), binary()}]

method()

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

Callbacks

request(method, binary, body, headers, t)

@callback request(method(), binary(), body(), headers(), Keyword.t()) ::
  {:ok, map()} | {:error, any()}

Functions

decode_response(response, opts)

Decodes request response body.

Options

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

@spec request(atom(), binary(), binary() | nil, list(), Keyword.t()) ::
  {:ok, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, Assent.HTTPAdapter.HTTPResponse.t()}
  | {:error, term()}

Makes a HTTP request.

Options

user_agent_header()

@spec user_agent_header() :: {binary(), binary()}

Sets a user agent header.

The header value will be Assent-VERSION with VERSION being the :vsn of :assent app.