HTTPower.Adapter.Req (HTTPower v0.16.0)
View SourceReq 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
- Automatic JSON encoding/decoding
- Response body decompression (gzip, brotli, zstd)
- SSL/TLS support with configurable verification
- Proxy support (system or custom)
- 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,nil, or custom options)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.