Documentation
¶
Overview ¶
Package apiclient provides small client-side helpers for api-toolkit APIs.
The package is stable core API for consumers that want composable helpers without generated service-specific SDKs. It decodes Problem Details responses, parses Retry-After, builds precondition headers, adds API key credentials, signs webhook requests, performs simple JSON requests, and iterates cursor-paginated resources.
Start with DoJSON for small JSON request/response flows, DecodeProblem when handling non-2xx responses, APIKeyTransport for service-to-service API key calls, WebhookSignerTransport for signed outbound webhook calls, and CursorIterator for cursor pages.
apiclient does not implement persistence, background retries, circuit breaking, generated resource clients, or provider-specific authentication. Keep those concerns in application clients or generated SDKs. For examples, see docs/cookbook.md.
Index ¶
- func DoJSON[T any](ctx context.Context, client *http.Client, method, url string, requestBody any) (T, *http.Response, error)
- func PreconditionHeaders(etag string, lastModified time.Time) http.Header
- func RetryAfter(header http.Header) (time.Duration, bool)
- type APIKeyTransport
- type CursorIterator
- type CursorPage
- type CursorPageFunc
- type ProblemError
- type WebhookSignerTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoJSON ¶
func DoJSON[T any](ctx context.Context, client *http.Client, method, url string, requestBody any) (T, *http.Response, error)
DoJSON sends a JSON request and decodes a JSON response.
func PreconditionHeaders ¶
PreconditionHeaders builds conditional request headers.
Types ¶
type APIKeyTransport ¶
type APIKeyTransport struct {
Key string
HeaderName string
Scheme string
Base http.RoundTripper
}
APIKeyTransport adds API key credentials to outbound requests.
type CursorIterator ¶
type CursorIterator[T any] struct { Fetch CursorPageFunc[T] Cursor string // contains filtered or unexported fields }
CursorIterator iterates cursor-paginated resources.
func (*CursorIterator[T]) Err ¶
func (it *CursorIterator[T]) Err() error
Err returns the terminal iterator error.
func (*CursorIterator[T]) Items ¶
func (it *CursorIterator[T]) Items() []T
Items returns the current page items.
type CursorPage ¶
CursorPage is one cursor-paginated client page.
type CursorPageFunc ¶
CursorPageFunc fetches one cursor-paginated page.
type ProblemError ¶
ProblemError wraps a Problem Details response as an error.
func DecodeProblem ¶
func DecodeProblem(resp *http.Response) (*ProblemError, error)
DecodeProblem decodes a Problem Details response.
func (*ProblemError) Error ¶
func (err *ProblemError) Error() string
type WebhookSignerTransport ¶
type WebhookSignerTransport struct {
Signer webhooks.Signer
HeaderName string
Base http.RoundTripper
}
WebhookSignerTransport signs outbound request bodies.