Skip to content

Commit

Permalink
Merge pull request #1015 from woylie/fix-req-example
Browse files Browse the repository at this point in the history
update Req HttpClient example
  • Loading branch information
bernardd authored Dec 11, 2023
2 parents 6496e9b + b65b406 commit d8ebade
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/ex_aws/request/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ defmodule ExAws.Request.HttpClient do
The default is `:hackney`.
## Example
## Example: Req
Here is an example using [Req](https://hexdocs.pm/req/readme.html).
First, create a module implementing the `ExAws.Request.HttpClient` behaviour.
```
defmodule ExAws.Request.Req do
@moduledoc \"""
ExAws HTTP client implementation for Req.
\"""
@behaviour ExAws.Request.HttpClient
@impl ExAws.Request.HttpClient
def request(method, url, body, headers, _http_opts) do
Req.request(method: method, url: url, body: body, headers: headers)
case Req.request(
method: method,
url: url,
body: body,
headers: headers,
decode_body: false
) do
{:ok, %Req.Response{status: status} = response} ->
{:ok,
response
|> Map.take([:body, :headers])
|> Map.put(:status_code, status)}
{:error, exception} ->
{:error, %{reason: exception}}
end
end
end
```
Expand All @@ -41,7 +61,7 @@ defmodule ExAws.Request.HttpClient do
- Ensure the call to your chosen HTTP Client is correct and the return is
in the same format as defined in the `c:request/5` callback
## Example
## Example: Mojito
def request(method, url, body, headers, http_opts \\ []) do
Mojito.request(method, url, headers, body, http_opts)
Expand Down

0 comments on commit d8ebade

Please sign in to comment.