HTTP adapter helper module.
You can configure which HTTP adapter Assent uses by setting the configuration:
http_adapter: Assent.HTTPAdapter.HttpcDefault 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.HttpcUsage
defmodule MyApp.MyHTTPAdapter do
@behaviour Assent.HTTPAdapter
@impl true
def request(method, url, body, headers, opts) do
# Implement your HTTP request logic here using your preferred
# HTTP client library. Return {:ok, response} or {:error, reason}.
end
end
Summary
Callbacks
Sends an HTTP request using the adapter's client.
Functions
Decodes request response body.
Formats an HTTP request for an error message.
Formats an HTTP response for an error message.
Makes an HTTP request.
Sets a user agent header.
Types
Callbacks
Functions
@spec decode_response(Assent.HTTPAdapter.HTTPResponse.t(), Keyword.t()) :: {:ok, Assent.HTTPAdapter.HTTPResponse.t()} | {:error, Assent.HTTPAdapter.InvalidResponseError.t()}
Decodes request response body.
Options
:json_library- the JSON library to use, seeAssent.json_library/1
@spec format_http_request(Assent.HTTPAdapter.HTTPRequest.t()) :: binary()
Formats an HTTP request for an error message.
@spec format_http_response(Assent.HTTPAdapter.HTTPResponse.t()) :: binary()
Formats an HTTP response for an error message.
@spec request(Assent.HTTPAdapter.HTTPRequest.t(), Keyword.t()) :: {:ok, Assent.HTTPAdapter.HTTPResponse.t()} | {:error, Assent.HTTPAdapter.HTTPResponse.t()} | {:error, term()}
Makes an HTTP request.
Options
:http_adapter- HTTP adapter configuration. Defaults to{Assent.HTTPAdapter.Req, []},{Assent.HTTPAdapter.Httpc, []}depending on which HTTP client is available in the project dependencies.:json_library- the JSON library to use, seeAssent.json_library/1
Sets a user agent header.
The header value will be Assent-VERSION with VERSION being the :vsn of
:assent app.