# `Assent.HTTPAdapter`
[🔗](https://github.com/pow-auth/assent/blob/v0.4.0/lib/assent/http_adapter.ex#L1)

HTTP adapter helper module.

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

    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
        # Implement your HTTP request logic here using your preferred
        # HTTP client library. Return {:ok, response} or {:error, reason}.
      end
    end

# `body`

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

# `headers`

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

# `method`

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

# `request`

```elixir
@callback request(method(), binary(), body(), headers(), Keyword.t()) ::
  {:ok, Assent.HTTPAdapter.HTTPResponse.t()} | {:error, term()}
```

Sends an HTTP request using the adapter's client.

# `decode_response`

```elixir
@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, see `Assent.json_library/1`

# `format_http_request`

```elixir
@spec format_http_request(Assent.HTTPAdapter.HTTPRequest.t()) :: binary()
```

Formats an HTTP request for an error message.

# `format_http_response`

```elixir
@spec format_http_response(Assent.HTTPAdapter.HTTPResponse.t()) :: binary()
```

Formats an HTTP response for an error message.

# `request`

```elixir
@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, see `Assent.json_library/1`

# `request`

> This function is deprecated. Use `request/2` instead. This will be removed in v1.0.0..

# `user_agent_header`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
