@askrjs/fetch/middleware
Exports from the declarations published in @askrjs/fetch. Signatures reflect the published artifact.
Exports
This entrypoint publishes 7 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"; }) => MiddlewareMiddleware 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>); }) => MiddlewareMiddleware 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; }) => MiddlewareMiddleware 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) => MiddlewareMiddleware 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.
RetryOptionstype
RetryOptions: anyOptions controlling the {@link retry} middleware's behavior.
attempts- Maximum number of attempts, including the first. Defaults to 3.
methods- HTTP methods eligible for retry. Defaults to idempotent-by-convention methods.
statuses- Response statuses that trigger a retry. Defaults to common transient failure codes.
delay- Computes the delay (ms) before the given retry attempt, if no `Retry-After` header is present.
maxRetryAfter- Maximum delay (ms) accepted from `Retry-After`. Defaults to 60 seconds.
telemetrytype
telemetry: (hooks: TelemetryHooks) => MiddlewareMiddleware that wraps each request with {@link TelemetryHooks}, calling `start` before the request, `end` after it completes, and `error` (then rethrowing) if it throws.
TelemetryHookstype
TelemetryHooks: anyHooks invoked by the {@link telemetry} middleware around each request.
start- Called before the request proceeds; its return value (a "span") is passed to `end`/`error`.
end- Called after the request completes successfully (from this middleware's perspective).
error- Called if a downstream middleware or the transport throws.