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 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.

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.

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.

  • url is the request URL without its query string.
  • duration is 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.

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.

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

On this page