apiclient

package
v3.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

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

func PreconditionHeaders(etag string, lastModified time.Time) http.Header

PreconditionHeaders builds conditional request headers.

func RetryAfter

func RetryAfter(header http.Header) (time.Duration, bool)

RetryAfter parses a Retry-After header value.

Types

type APIKeyTransport

type APIKeyTransport struct {
	Key        string
	HeaderName string
	Scheme     string
	Base       http.RoundTripper
}

APIKeyTransport adds API key credentials to outbound requests.

func (APIKeyTransport) RoundTrip

func (transport APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

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.

func (*CursorIterator[T]) Next

func (it *CursorIterator[T]) Next(ctx context.Context) bool

Next fetches the next page.

type CursorPage

type CursorPage[T any] struct {
	Items      []T
	NextCursor string
}

CursorPage is one cursor-paginated client page.

type CursorPageFunc

type CursorPageFunc[T any] func(context.Context, string) (CursorPage[T], error)

CursorPageFunc fetches one cursor-paginated page.

type ProblemError

type ProblemError struct {
	StatusCode int
	Problem    httpx.Problem
}

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.

func (WebhookSignerTransport) RoundTrip

func (transport WebhookSignerTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL