HTTP client
August 31, 2025 ยท View on GitHub
Traced HTTP client with correlation propagation, optional circuit breaker, and auto-decompression helpers.
- Package:
github.com/beatlabs/patron/client/http - Type:
TracedClient, implementsDo(req *http.Request) (*http.Response, error)
Quick start
import (
clienthttp "github.com/beatlabs/patron/client/http"
)
cl, _ := clienthttp.New(
clienthttp.WithTimeout(30*time.Second),
)
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "https://example.com/api", nil)
req.Header.Set("Accept-Encoding", "gzip")
rsp, err := cl.Do(req)
if err != nil { /* handle */ }
defer rsp.Body.Close()
Notes
- Tracing: uses
otelhttp.NewTransportunder the hood; spans are created for outbound requests. - Correlation: adds the
X-Correlation-IDheader from request context automatically. - Decompression: if
Accept-Encodingis set togzipordeflate, response body is decompressed.
Options
WithTimeout(d time.Duration)WithCircuitBreaker(name string, set circuitbreaker.Setting)WithTransport(rt http.RoundTripper)(wrapped withotelhttp.NewTransport)WithCheckRedirect(func(req *http.Request, via []*http.Request) error)
See tests in client/http and usage in examples for more.