Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Req HttpClient example #1015

Merged
merged 1 commit into from
Dec 11, 2023
Merged

update Req HttpClient example #1015

merged 1 commit into from
Dec 11, 2023

Conversation

woylie
Copy link
Contributor

@woylie woylie commented Nov 21, 2023

This updates the Req example in the ExAws.Request.HttpClient documentation.

  • Set decode_body: false to prevent Req from decoding JSON responses on its own (behaviour expects binary body).
  • Rename status to status_code in response to conform to behaviour. I know ex_aws was updated to map the response on its own in the main branch, but the behaviour still prescribes a status_code field.
  • Wrapped error into reason map as prescribed by behaviour.
  • Added missing @impl.
  • Added moduledoc to example for easier copy-and-paste into projects that enforce module docs with linter rules.
  • Updated headers to avoid duplicate links in the sidebar.

@bernardd
Copy link
Contributor

Thanks @woylie! Apologies for the delay in getting to this.

@bernardd bernardd merged commit d8ebade into ex-aws:main Dec 11, 2023
12 checks passed
@woylie woylie deleted the fix-req-example branch December 11, 2023 03:32
reisub added a commit to reisub/ex_aws that referenced this pull request Jan 3, 2024
This builds on work in ex-aws#1015 adding a bit of code to adjust the header
format to the expected list of 2-element tuples.

Req 0.4+ changed the header format to be a map where the key is a string
and the value is a list of strings, e.g.:

```elixir
%{
  "content-length" => ["12345"]
}
```

This change makes the current example fail whenever you try to perform a
streaming operation because this code in `ExAws.S3.Download` assumes a
single value:

```elixir
defp get_file_size(bucket, path, config) do
  %{headers: headers} = ExAws.S3.head_object(bucket, path) |> ExAws.request!(config)

  headers
  |> Enum.find(fn {k, _} -> String.downcase(k) == "content-length" end)
  |> elem(1)
  |> String.to_integer()
end
```

With the proposed change, the example implementation should handle both new and old
Req versions; though I've only tested with a recent one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants