Req adapter for HTTPower.
This adapter uses the Req HTTP client library to make HTTP requests. Req is a "batteries-included" HTTP client with features like automatic body encoding/decoding, compression, and more.
Features
- JSON encoding/decoding handled by
HTTPower.Codec(Req's own request retry and response decoding are disabled to avoid conflicts/double-decoding) - Response body decompression (gzip, brotli, zstd)
- SSL/TLS support with configurable verification
- Proxy support (per-request, forwarded to Mint)
- Integration with
Req.Testfor testing
Configuration
The Req adapter accepts standard HTTPower options plus any Req-specific options:
timeout- Request timeout in seconds (converted to milliseconds for Req)ssl_verify- Enable SSL verification (default: true)proxy- Proxy configuration.:system(the default) andnilboth mean a direct connection with no proxy — there is no system-proxy auto-detection. An explicit proxy must be a Mint{scheme, address, port, opts}tuple, which is forwarded toconnect_options[:proxy].plug- Req.Test plug for testing (e.g.,{Req.Test, MyApp})
Testing
The Req adapter works seamlessly with Req.Test for mocking HTTP requests in tests:
# In your test
Req.Test.stub(MyApp, fn conn ->
Req.Test.json(conn, %{status: "success"})
end)
HTTPower.get("https://api.example.com",
adapter: HTTPower.Adapter.Req,
plug: {Req.Test, MyApp})Important
This adapter disables Req's built-in retry logic by setting retry: false.
HTTPower's own retry logic (with exponential backoff and jitter) is used instead,
ensuring consistent retry behavior across all adapters.