Rene Nochebuena 962b0ccf17 feat(httpclient)!: promote to v1.0.0 — retry-on-429 with Retry-After, DoJSONRequest, bump deps
Extend retry loop to handle HTTP 429 Too Many Requests: when the server includes a
Retry-After header, that duration is used as the retry delay; otherwise falls back to
the configured BackOffDelay. Add DoJSONRequest[Req, Resp] free function that serialises
the request body as JSON, sets Content-Type, and delegates response decoding to DoJSON.
Bump logz and xerrors from v0.9.0 to v1.0.0. API committed as stable.
2026-05-11 19:50:16 -06:00

httpclient

Resilient HTTP client with automatic retry and circuit breaking.

Install

go get code.nochebuena.dev/go/httpclient

Usage

client := httpclient.NewWithDefaults(logger)
// or with custom config:
client = httpclient.New(logger, httpclient.Config{
    Name:        "payment-api",
    MaxRetries:  3,
    CBThreshold: 10,
})

resp, err := client.Do(req)

Typed JSON helper

order, err := httpclient.DoJSON[Order](ctx, client, req)

Error mapping

httpclient.MapStatusToError(404, "not found") // → xerrors.ErrNotFound
HTTP status xerrors code
404 ErrNotFound
400 ErrInvalidInput
401 ErrUnauthorized
403 ErrPermissionDenied
409 ErrAlreadyExists
429 ErrUnavailable
5xx ErrInternal

Configuration

Env var Default Description
HTTP_CLIENT_NAME http Circuit breaker name
HTTP_TIMEOUT 30s Overall request timeout
HTTP_DIAL_TIMEOUT 5s TCP dial timeout
HTTP_MAX_RETRIES 3 Retry attempts
HTTP_RETRY_DELAY 1s Base retry delay
HTTP_CB_THRESHOLD 10 Consecutive failures before open
HTTP_CB_TIMEOUT 1m Time before half-open retry
Description
Resilient HTTP client with circuit breaker and retry.
Readme MIT 57 KiB
2026-05-11 19:51:01 -06:00
Languages
Go 100%