Skip to Content
Reference

Plugins

Every export of @monarcode/effetch/plugins: the built-in plugins and their options.

@monarcode/effetch/plugins exports the built-in plugins, their options, the types they return and TimeoutError. Import what you use:

import {
  ,
  ,
  ,
  ,
  ,
  ,
} from "@monarcode/effetch/plugins";

Its exports follow, grouped by the guide that covers them. Each one has the first paragraph of its docs, and what it needs and how it fails; your editor shows the rest, with an example, when you hover the name.

Bearer tokens

Guide: Refresh a token.

bearer

Sends Authorization: <scheme> <token> with every request.

BearerOptions

Options for bearer.

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: the idempotent ones by default, so retry doesn't resend a POST unless you add it. With a budget, it also limits the whole call, every attempt and wait included, and fails with TimeoutError when the budget runs out.

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.

Prop

Type

RetryPlugin

The plugin made by retry. It adds no errors; calls can override times or skip it.

Time limits

Guide: Retry-After and a time limit.

timeout

Fails the call with a TimeoutError, and aborts the request, when the response headers don't arrive within duration.

TimeoutError

The error a call fails with when a time limit runs out: the timeout plugin's duration before the response headers arrive, or retry's budget for the whole call. The request in flight is aborted. Its fields:

  • method: the request's HTTP method.
  • url: the request URL without its query string.
  • duration: the limit that ran out, 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, for example GET https://api.example.com/todos 200 (35ms), or … failed (35ms) with the failure's cause. An interrupted call isn't logged. Placed after retry, it logs each attempt instead of the call.

LoggerOptions

Options for logger.

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.

It logs each call after it's over, with its final outcome: the error a call fails with after statusErrors and decoding, or interrupted. Values are logged as objects, for devtools to expand. Everything goes through Effect's Console with console.log and groups, never console.error, which React Native turns into an error screen.

It runs from the onExit hook, so it covers the whole call wherever it sits in the plugin list: retries are one entry, and duration includes them. When a plugin fails on a response (such as a 401), that response is shown. Without a response, the request shown is the one the call built, before plugins (such as bearer) changed it.

Throws if slow isn't a duration. A call's own slow that isn't one flags nothing.

ConsoleLoggerCall

The call ConsoleLoggerOptions.filter decides on.

Prop

Type

ConsoleLoggerColor

How consoleLogger colors its output.

  • "auto": "css" where there's a document (browsers), else false.
  • "css": %c styles, 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.

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

  • Entry points: what each entry point exports.
  • Fetch: every member of the Fetch namespace.
  • FetchTest: the fake backend for tests.
  • Compatibility: the Effect, runtime and TypeScript versions Effetch supports.

On this page