Premailex.HTTPAdapter behaviour (Premailex v1.0.0)

Copy Markdown View Source

HTTP client adapter behaviour.

Usage

defmodule MyHTTPAdapter do
  @behaviour Premailex.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

Configure Premailex to use a custom adapter:

config :premailex,
  http_adapter: MyHTTPAdapter

Summary

Types

An HTTP response returned by an adapter's request/5 callback.

Functions

Returns a User-Agent header tuple for use in HTTP requests.

Types

body()

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

headers()

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

method()

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

response()

@type response() :: %{status: non_neg_integer(), headers: headers(), body: binary()}

An HTTP response returned by an adapter's request/5 callback.

Callbacks

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

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

Makes an HTTP request.

Functions

user_agent_header()

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

Returns a User-Agent header tuple for use in HTTP requests.