Skip to content

Api plugins

An api plugin in Alette Signal is a module defining and configuring request blueprints before exposing them for usage. On its own blueprint() contains no middleware, and needs to be defined and configured by plugin authors using built-in middleware.

Core plugin blueprints

Alette Signal core plugin exposes 3 configured request blueprints out of the box:

  1. Query - preconfigured for GET HTTP requests.
  2. Mutation - preconfigured for POST, PATCH, DELETE and PUT HTTP requests.
  3. Custom - used for executing dependent requests, or creating custom request behaviours by composing middleware.
api/base.ts
ts
import { coreApiPlugin } from '@alette/signal';

export const core = coreApiPlugin();
export const { query, mutation, custom } = core.use();

INFO

Alette Signal treats query(), mutation() and custom() as middleware "black boxes", nothing more. The same is true for any blueprints plugin authors may define.

DANGER

A plugin must be activated for its request blueprints to work.

Api plugin activation

To activate api plugins, use activatePlugins() api instruction:

api/client.ts
ts
import { client, activatePlugins, coreApiPlugin } from "@alette/signal";
import { core } from './base.ts'

export const api = client(
    /* ... */
    activatePlugins(core.plugin),
);

DANGER

Api plugins must be activated for their request blueprints to work.

Api plugin deactivation

To deactivate api plugins, use deactivatePlugins() api instruction:

ts
api.tell(deactivatePlugins(core.plugin))

DANGER

During plugin deactivation all in-flight requests created from its request blueprints are interrupted.

Released under the Apache 2.0 License.