Plugins
Every export of @monarcode/effetch/plugins: the built-in plugins and their options.
@monarcode/effetch/plugins exports the built-in plugins, their options and the types they return:
import {
,
,
,
,
,
,
} from "@monarcode/effetch/plugins";Bearer tokens
Guide: Refresh a token.
bearer
Sends Authorization: <scheme> <token> with every request.
BearerOptions
Options for bearer.
token: where the token comes from (seeTokenSource). It's resolved for every request, inside that request's fiber, and never cached, so a refreshed or cleared token takes effect on the next request.scheme: the word before the token. Defaults to"Bearer".refresh: where a new token comes from when the server answers401to a request thatbearersent a token with (seeRefreshSource). The request is then sent once more, with the new token. Withoutrefresh, a401is returned as it is.
Prop
Type
BearerPlugin
The plugin made by bearer: it fails with E and needs R, the errors and services of the token and refresh Effects. Calls can only skip it (plugins: { bearer: false }).
RefreshSource
Where bearer gets a new token when the server answers 401:
- a function of the request that was refused, as it was sent, returning the new token or a promise of it;
- an Effect, whose error and services become the plugin's (and so the client's).
TokenSource
Where bearer gets the token, for every request:
- a string, for a token that never changes;
- a function of the request, returning the token or a promise of it;
- an Effect, whose error and services become the plugin's (and so the client's).
TokenValue
What a token source gives: the token, or null, undefined or "" to send the request without an Authorization header.
Retries
Guide: Retry-After and a time limit.
retry
Retries a call that failed with a NetworkError or got a retryable status, for the configured methods only (idempotent ones by default, so a POST is never sent twice).
RetryBudgetOptions
Options for retry with a time limit for the whole call: RetryOptions, plus budget.
Prop
Type
RetryBudgetPlugin
The plugin made by retry with a budget. It fails with TimeoutError when the budget runs out during an attempt. Calls can override times and budget, or skip it.
RetryOptions
Options for retry.
times: how many times to retry, after the first attempt. Defaults to2. Calls can override it.schedule: the delays between attempts. Defaults to an exponential backoff from 200ms, with jitter.timesstill caps the retries.methods: the methods that are retried. Defaults to the idempotent ones:GET,HEAD,OPTIONS,PUTandDELETE.statuses: the response statuses that are retried. Defaults to408,429,500,502,503and504.retryAfter: whether to wait as long as a retried response'sRetry-Afterheader asks, in place of the schedule's next delay.truecaps the wait at 1 minute, and{ max }atmax. Defaults tofalse.
Prop
Type
RetryPlugin
The plugin made by retry. It adds no errors; calls can override times or skip it.
Time limits
Guide: Choose a time limit.
timeout
Fails the call with a TimeoutError, and aborts the request, when the response headers don't arrive within duration.
TimeoutError
No response arrived within the timeout plugin's duration. The request was aborted.
urlis the request URL without its query string.durationis the limit that was exceeded, formatted ("10s").
TimeoutOptions
Options for timeout, and what a call can override: plugins: { timeout: { duration } }.
Prop
Type
TimeoutPlugin
The plugin made by timeout: it adds TimeoutError, and calls can override its duration or skip it.
Logging
Guide: Built-in plugins.
logger
Logs one entry per call with Effect's logger: the method, the URL, the status and how long the response took, e.g. GET https://api.example.com/todos 200 (35ms), or … failed (35ms) with the failure's cause.
LoggerOptions
Options for logger.
level: the log level of every entry,"Debug"(the default) or"Info". Effect's default logger hides Debug entries unless the minimum log level allows them.
Prop
Type
LoggerPlugin
The plugin made by logger. Calls can only skip it (plugins: { logger: false }).
Console logging
Guide: Log to the console.
consoleLogger
Prints each call to the console while you develop: one line per call, opening a group with its URL, headers, bodies and error.
ConsoleLoggerCall
The call ConsoleLoggerOptions.filter decides on.
route: the call's method and unfilled path, such as"GET /users/:id".request: the request that was sent, after every plugin changed it. Without a response, it's the request as the call built it, before plugins ran.response: the response, orundefinedwhen there was none.exit: the call's outcome.durationMs: how long the call took, in milliseconds.
Prop
Type
ConsoleLoggerColor
How consoleLogger colors its output.
"auto":"css"where there's adocument(browsers), elsefalse."css":%cstyles, for browser devtools and React Native DevTools."ansi": terminal escape codes, for Node, Bun and Deno.false: plain text.
ConsoleLoggerDetail
How much consoleLogger prints for each call.
"summary": one line, such as✗ POST /users/:id/roles 400 Bad Request 120 ms → InvalidRole."headers": that line opens a group holding the full URL, the request and response headers, and the error."full": the request and response bodies too.
ConsoleLoggerOptions
Options for consoleLogger. All are optional.
enabled:falsemakes the plugin do nothing, keeping its type, so it can stay in the plugin list in production. Defaults totrue.detail:"summary","headers"or"full"(the default). SeeConsoleLoggerDetail.only:"all"calls (the default), or"errors"for failed ones only. An interrupted call isn't a failed one.collapsed: whether groups start collapsed. Defaults totrue, and tofalsein React Native: Metro's terminal dropsconsole.groupCollapsedand everything logged inside it. Node, Bun and Deno print collapsed groups expanded.slow: calls that take at least this long are flagged with⚠and(slow). Defaults tofalse, flagging none.maxBodyLength: body text longer than this many characters is cut. A JSON body within it is printed as an object, for devtools to expand; a longer one as its cut text. Defaults to10_000.redact: names to redact on top of the defaults, orfalseto redact nothing. SeeConsoleLoggerRedact.filter: prints only the calls it returnstruefor.color: seeConsoleLoggerColor. Defaults to"auto".
Prop
Type
ConsoleLoggerPlugin
The plugin made by consoleLogger. Calls can skip it (plugins: { consoleLogger: false }) or override its ConsoleLoggerSettings.
ConsoleLoggerRedact
Names to redact on top of consoleLogger's defaults. Strings match a name ignoring case, - and _, so "accessToken" also matches access_token and Access-Token. A RegExp is tested against the name as it is.
Prop
Type
ConsoleLoggerSettings
The options of consoleLogger that calls can override, with plugins: { consoleLogger: { ... } }. See ConsoleLoggerOptions for what each does.
Prop
Type