Documentation
¶
Index ¶
Constants ¶
const DefaultMaxResponseBytes int64 = 32 << 20 // 32 MiB
DefaultMaxResponseBytes caps response body reads. Set via WithMaxResponseBytes; pass 0 to disable the cap entirely.
Variables ¶
This section is empty.
Functions ¶
func HTTPClient ¶
Types ¶
type Option ¶ added in v0.7.0
type Option func(*REST)
Option configures a REST client.
func WithBaseURL ¶ added in v0.7.0
WithBaseURL sets a base URL that relative request URLs are resolved against. Absolute request URLs are passed through unchanged.
func WithHTTPClient ¶ added in v0.7.0
WithHTTPClient overrides the underlying *http.Client.
func WithHeader ¶ added in v0.7.0
WithHeader sets a default header applied to every request. Per-request headers already set on the *http.Request take precedence.
func WithHeaders ¶ added in v0.7.0
WithHeaders merges the given headers into the default header set.
func WithLogger ¶ added in v0.7.0
WithLogger overrides the slog.Logger used for request logging.
func WithMaxResponseBytes ¶ added in v0.7.0
WithMaxResponseBytes caps the number of response body bytes read into memory. Pass 0 to disable the cap.
type REST ¶ added in v0.7.0
type REST struct {
// contains filtered or unexported fields
}
REST is an embeddable HTTP client for REST APIs. Concrete clients embed *REST and expose typed methods that build an *http.Request and call Process.
func New ¶ added in v0.7.0
New creates a REST client with the given options. By default it uses HTTPClient() (retrying, OTel-instrumented), an empty header set, a discard logger, and a DefaultMaxResponseBytes response cap.
func (*REST) Process ¶ added in v0.7.0
Process sends req and writes the response into out, choosing how based on the type of out:
- nil: response body is discarded.
- *[]byte: raw bytes.
- *string: raw string.
- io.Writer: streamed via io.Copy.
- anything else: JSON-decoded.
Non-2xx responses return an *errors.Error carrying the status code and body. Response body reads are capped by WithMaxResponseBytes (0 disables the cap). The response body is always closed.