Skip to content

feat: introduce pluggable HTTP client behaviour#150

Open
klacointe wants to merge 1 commit into
elixir-waffle:masterfrom
klacointe:feat/pluggable-http-client-adapter
Open

feat: introduce pluggable HTTP client behaviour#150
klacointe wants to merge 1 commit into
elixir-waffle:masterfrom
klacointe:feat/pluggable-http-client-adapter

Conversation

@klacointe

@klacointe klacointe commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Follow up of Add pluggable HTTP client behaviour with Hackney and Finch implementations #148
  • Adds Waffle.HTTPClient behaviour with a single get/3 callback
  • Adds Waffle.HTTPClient.Hackney as the default implementation (existing behaviour, just moved into a dedicated module)
  • Refactors Waffle.File to dispatch through the configured :http_client instead of calling hackney directly; retry logic stays client-agnostic
  • Documents how to implement a custom HTTP client adapter

Usage

Configure a custom client:

config :waffle, :http_client, MyApp.HTTPClient

Implement the behaviour:

defmodule MyApp.HTTPClient do
  @behaviour Waffle.HTTPClient

  @impl Waffle.HTTPClient
  def get(url, headers, options) do
    # ...
  end
end

Error shape changes

Error case Before After
Connect timeout {:error, :timeout} {:error, :timeout} — unchanged
Receive timeout {:error, :recv_timeout} {:error, :recv_timeout} — unchanged
503 out of retries {:error, {:waffle_hackney_error, {:ok, 503, headers, ref}}} {:error, :service_unavailable}
Non-2xx response {:error, {:waffle_hackney_error, {:ok, status, headers, ref}}} {:error, {:http_error, status}} e.g. {:error, {:http_error, 404}}

The previous 503 and non-2xx shapes leaked a closed hackney client_ref inside the error tuple.

Notes

#75

@klacointe

Copy link
Copy Markdown
Contributor Author

@achempion when you'll be ok with this one I'll propose the Finch adapter.

@klacointe klacointe marked this pull request as draft June 17, 2026 19:44
@klacointe klacointe marked this pull request as ready for review June 17, 2026 19:52
@klacointe klacointe force-pushed the feat/pluggable-http-client-adapter branch from 9c5b76f to df970da Compare June 17, 2026 19:54
- Add Waffle.HTTPClient behaviour with a single get/3 callback
- Add Waffle.HTTPClient.Hackney as the default implementation
- Refactor Waffle.File to dispatch through the configured :http_client
  instead of calling hackney directly; retry logic stays client-agnostic
- Document how to implement a custom HTTP client adapter
@klacointe klacointe force-pushed the feat/pluggable-http-client-adapter branch from df970da to e6a6bd6 Compare June 17, 2026 20:41
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.

1 participant