Askr documentation
Generated API snapshot

@askrjs/fetch/middleware

Exports from the declarations published in @askrjs/fetch. Signatures reflect the published artifact.

Exports

This entrypoint publishes 5 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

apiKeyAuthtype

apiKeyAuth: ({ key, value, in: location }: { key: string; value: string | (() => string | Promise<string>); in?: "header" | "query"; }) => Middleware

Middleware that attaches an API key to every request, either as a header or a query parameter (in, default "header"). value may be a static string or a (possibly async) function resolved on each request. The key is marked sensitive so the {@link logging} middleware redacts it.

bearerAuthtype

bearerAuth: ({ token }: { token: string | (() => string | Promise<string>); }) => Middleware

Middleware that attaches an Authorization: Bearer <token> header to every request. token may be a static string or a (possibly async) function resolved on each request.

loggingtype

logging: (logger?: { log(event: Record<string, unknown>): void; }) => Middleware

Middleware that logs a "request" event before and a "response" event after each request, via the given logger (defaults to console). Headers and query parameters marked sensitive (e.g. by {@link apiKeyAuth}) or matching common sensitive-name patterns (authorization, cookie, token, secret, password, api key) are redacted.

retrytype

retry: (options?: RetryOptions) => Middleware

Middleware that retries failed requests. Retries eligible methods on network failures or eligible response statuses, honoring a Retry-After header when present and stopping early if the request's deadline would be exceeded. A non-streaming request body is replayed only when it can be cloned before the first attempt; streaming, already-consumed, or otherwise non-cloneable bodies are sent once without retrying.

telemetrytype

telemetry: (hooks: TelemetryHooks) => Middleware

Middleware that wraps each request with {@link TelemetryHooks}, calling start before the request, end after it completes, and error (then rethrowing) if it throws.