Change plugins for one call
Turn off or adjust a client's plugin for one call.
A client's plugins run on every call, but some calls need something different: a login that sends no token, or a slow export that needs more time. Rather than build a second client for them, you change the plugins for that one call. This page shows how, and how a call's changes combine with the plugin's defaults and with an endpoint's.
Skip or adjust a plugin
Pass plugins in the call's options, keyed by the plugin's name. false
skips that plugin, and an object changes some of its options:
import * as from "effect/Effect";
import { } from "@monarcode/effetch";
import { , , } from "@monarcode/effetch/plugins";
class extends .<>()("Api", {
: "https://api.example.com",
: [
(),
({ : "10 seconds" }),
({ : "token" }),
],
}) {}
export const = .(function* () {
const = yield* ;
// Logging in sends no token.
yield* .("/auth/login", {
: { : "ada" },
: { : false },
});
// A slow export gets more time, and isn't retried.
yield* .("/reports/export", {
: { : { : "2 minutes" }, : { : 0 } },
});
});TypeScript checks the plugin names and the option types, so a misspelled
name or a wrong option doesn't compile. Each plugin decides which options a
call can change. To see what each built-in plugin accepts, see the
Per call column in Built-in plugins.
A plugin you write accepts any of the options in its defaults (see
Write a plugin).
How a call's changes apply
A call's changes combine with the rest as follows:
- Options you leave out keep their defaults. A call that passes
{ consoleLogger: { detail: "summary" } }changesdetailonly, and keeps the other settings. A key set toundefinedis left out too, so it keeps the value it would have without it, and you can pass a value that may be missing, such as{ retry: { times: maybeTimes } }, as it is. Any object still turns the plugin on, even one whose keys are allundefined: on an endpoint bound withretry: false, that call retries. falseskips the whole plugin. Itswrap,onRequestandonResponsedon't run for that call, and neither do itsonErrorandonExit. A skippedconsoleLoggerprints nothing, for example.- A call's changes go on top of an endpoint's. When you bind an
endpoint with
pluginsoverrides, a call to it can pass its own. For each plugin, the call's value wins, and when both are option objects they're merged, key by key. See Call an endpoint.
What's next
- Write a plugin: write your own plugins, with options that calls can override.
- Retry-After and a time limit: override the whole-call budget for one call.
- Log to the console: change the console output for one call.