Under heavy development
StitchAPI
GuidesAuthoring & composition

preset()

Bundle reusable defaults under a name and apply them across many stitches.

Use preset() to bundle cross-cutting defaults — retries, timeouts, headers — under a name, then apply that bundle to many stitches instead of repeating the same fields on each one.

Example

import { , ,  } from 'stitchapi';

// A named bundle of reusable defaults. It does nothing on its own.
const  = ({
    : { : 3, : [429, 503] },
    : { : '10s' },
});

// Apply it to a single stitch via `extends`.
const  = ({
    : 'https://api.example.com',
    : '/users/{id}',
    : [],
});

// Or bind it as a base, so every stitch from this factory inherits it.
const  = ();

A preset() is just an identity-tagged fragment: a plain Partial<StitchConfig> that exists to be reused. You apply it with extends or bind it through defineStitch().

Options

preset() accepts a Partial<StitchConfig>, so anything a stitch accepts can live in one. Reach for it to centralize cross-cutting defaults: baseUrl, retry, throttle, timeout, headers, and auth.

Fragments deep-merge when applied, and later layers — including the stitch's own fields — win over the preset. So a stitch can adopt resilient and still override its timeout inline. See extends for the full deep-merge and override semantics, and Reference → Config types for every field a preset may carry.

A preset() is inert until applied — nothing runs at definition time. It is only the bundle; extends and defineStitch() are what consume it.

See also

On this page