ExAws v2.1.3 ExAws.Request.HttpClient behaviour View Source

Specifies expected behaviour of an http client

ExAws allows you to use your http client of choice, provided that it can be coerced into complying with this module's specification.

The default is :hackney.


Here for example is the code required to make HTTPotion comply with this spec.

In your config you would do:

config :ex_aws,
  http_client: ExAws.Request.HTTPotion
defmodule ExAws.Request.HTTPotion do
  @behaviour ExAws.Request.HttpClient
  def request(method, url, body, headers, http_opts) do
    {:ok, HTTPotion.request(method, url, [body: body, headers: headers, ibrowse: [headers_as_is: true]])}

When conforming your selected HTTP Client take note of a few things:

  • The module name doesn't need to follow the same styling as this module it is simply your own 'HTTP Client', i.e. MyApp.HttpClient
  • The request function must accept the methods as described in the @callback below, you can however set these as optional, i.e. (http_opts \ [])
  • Ensure the call to your chosen HTTP Client is correct and the return is in the same format as defined in the @callback below, for example:
def request(method, url, body, headers, http_opts \ []) do
  Mojito.request(method, url, headers, body, http_opts)

Link to this section Summary

Link to this section Types

Link to this type


View Source
http_method() :: :get | :post | :put | :delete

Link to this section Callbacks

Link to this callback

request(method, url, req_body, headers, http_opts)

View Source
  method :: http_method(),
  url :: binary(),
  req_body :: binary(),
  headers :: [{binary(), binary()}, ...],
  http_opts :: term()
) ::
  {:ok, %{status_code: pos_integer(), body: binary()}}
  | {:error, %{reason: any()}}