HttpClient module provides a functional, composable HTTP client built on Effect. It features automatic retries, rate limiting, tracing, cookie management, and powerful transformation APIs.
Overview
HttpClient offers:- Composable request/response transformations
- Built-in retry strategies for transient errors
- Rate limiting with automatic header inspection
- Distributed tracing integration
- Cookie jar management
- Type-safe error handling
- Request/response streaming
Basic Usage
Making Requests
HttpClient provides convenience methods for all HTTP verbs:get
post
Other Methods
put- HTTP PUT requestspatch- HTTP PATCH requestsdel- HTTP DELETE requestshead- HTTP HEAD requestsoptions- HTTP OPTIONS requests
Request Transformation
mapRequest
Transforms the request before sending.
mapRequestEffect
Transforms the request with an Effect.
Response Transformation
transform
Transforms both request and response.
Error Handling
catch
Handles errors with a recovery function.
catchTag
Handles specific error types by tag.
catchTags
Handles multiple error types.
Filtering Responses
filterStatus
Filters responses by status code predicate.
filterStatusOk
Filters to only 2xx status codes.
Retry Strategies
retry
Retries requests based on a schedule or policy.
retryTransient
Automatically retries transient errors (timeouts, 429, 500-504).
- Network timeouts
- HTTP 408 (Request Timeout)
- HTTP 429 (Too Many Requests)
- HTTP 500 (Internal Server Error)
- HTTP 502 (Bad Gateway)
- HTTP 503 (Service Unavailable)
- HTTP 504 (Gateway Timeout)
Rate Limiting
withRateLimiter
Applies rate limiting using the RateLimiter service.
- Automatic limit updates from response headers (
RateLimit-*,X-RateLimit-*) - Automatic retry of 429 responses
- Support for fixed-window and token-bucket algorithms
- Per-request token consumption
Cookie Management
withCookiesRef
Attaches a Ref for cookie jar management.
Redirects
followRedirects
Automatically follows HTTP redirects.
Scoped Requests
withScope
Ties the request lifetime to a Scope.
Tracing
HttpClient automatically integrates with Effect’s tracing system:Customizing Tracing
Side Effects
tap
Performs a side effect on successful responses.
tapError
Performs a side effect on errors.
tapRequest
Performs a side effect on requests before sending.
Creating Custom Clients
make
Creates a custom HttpClient implementation.
makeWith
Creates a client with custom pre/post processing.
Type Reference
HttpClient
See Also
- HttpClientRequest - Request construction and manipulation
- HttpClientResponse - Response handling
- Schedule - Retry schedules
- Effect - Core Effect operations
