Skip to content

Instantly share code, notes, and snippets.

@ntodd
Created March 2, 2023 19:39
Show Gist options
  • Save ntodd/1793a508a2481ee39c0b2785da15b6b3 to your computer and use it in GitHub Desktop.
Save ntodd/1793a508a2481ee39c0b2785da15b6b3 to your computer and use it in GitHub Desktop.
Req HTTPClient for Elixir AWS package
defmodule MyApp.AWS.HTTPClient do
@moduledoc """
Implements the `AWS.HTTPClient` behaviour for use with the `AWS` library.
This is a simple wrapper around the `Req` library. Helps us avoid having to
include Hackney as a dependency.
"""
@behaviour AWS.HTTPClient
@impl AWS.HTTPClient
def request(method, url, body, headers, options) do
case %Req.Request{
method: method,
url: url,
body: body,
headers: headers,
options: options
}
|> Req.Request.run() do
{:ok, %Req.Response{status: status_code, headers: headers, body: body}} ->
{:ok, %{status_code: status_code, headers: headers, body: body}}
{:error, exception} ->
{:error, exception}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment