Documentation
¶
Overview ¶
Package httpcl provides a minimal HTTP client with JSON defaults and retries. Inspired by backplane-go/httpcl but stripped to essentials, using hashicorp/go-retryablehttp for retry logic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasStatusCode ¶
HasStatusCode checks if err is an *HTTPError with any of the given status codes.
func JSONDecoder ¶
JSONDecoder decodes a 2xx response body as JSON into v.
func QueryParam ¶
QueryParam sets a single query parameter.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a simple HTTP client with JSON defaults and automatic retries.
type Config ¶
type Config struct {
// BaseURL is prepended to every request route.
BaseURL string
// AuthToken is sent as a Bearer token unless AuthHeader is set.
AuthToken string
// AuthHeader overrides the header name for AuthToken (e.g. "Circle-Token", "x-api-key").
// When set, the token is sent as the raw header value (not "Bearer ...").
AuthHeader string
// UserAgent sets the User-Agent header on every request.
UserAgent string
// Timeout is the per-request timeout. Defaults to 30s.
Timeout time.Duration
// Transport overrides the HTTP transport (useful for testing).
Transport http.RoundTripper
}
Config configures a Client.
type HTTPError ¶
type HTTPError struct {
Method string
Route string
StatusCode int
Body []byte // raw response body
}
HTTPError represents a non-2xx HTTP response.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is an individual HTTP request to be executed by Client.Call. Use NewRequest to create one.
func NewRequest ¶
NewRequest creates a request with functional options.