Skip to Content
Plugins

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" } } changes detail only, and keeps the other settings. A key set to undefined is 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 all undefined: on an endpoint bound with retry: false, that call retries.
  • false skips the whole plugin. Its wrap, onRequest and onResponse don't run for that call, and neither do its onError and onExit. A skipped consoleLogger prints nothing, for example.
  • A call's changes go on top of an endpoint's. When you bind an endpoint with plugins overrides, 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

On this page