Created
March 2, 2023 19:39
-
-
Save ntodd/1793a508a2481ee39c0b2785da15b6b3 to your computer and use it in GitHub Desktop.
Req HTTPClient for Elixir AWS package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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