Under heavy development
StitchAPI
GuidesAuthoring & composition

extends

Layer fragments — strings, objects, or other stitches — with deep-merge to compose configuration.

Use extends to build a stitch from layered fragments — a shared base, an options object, and the stitch's own inline fields — deep-merged in order so the common configuration lives in one place and each stitch states only what differs.

Example

import {  } from 'stitchapi';

// A base stitch carrying the shared host and headers.
const  = ({
    : 'https://api.example.com',
    : { : 'application/json' },
});

const  = ({
    : [, { : { : 3 } }],
    : '/users/{id}',
});

getUser deep-merges three layers: base's config, the inline retry object, and its own path. The result carries baseUrl, headers, retry, and path.

Options

extends takes an array of fragments, each normalized to a partial config: a string becomes { path: string }; another stitch contributes its resolved config; a plain object is used as-is. Nested extends inside any fragment are flattened first, so a base can itself extend another base.

Layers are deep-merged left to right, and later layers win — the stitch's own inline fields are the last layer, so they override everything they extend. Two exceptions: hooks chain instead of overwriting (every layer's onRequest/onResponse/onError/onRetry runs), and store is taken from the last layer that sets one.

preset() and defineStitch() are conveniences built on this: a preset is a named fragment you drop into extends, and defineStitch() pre-binds base fragments so every stitch it produces extends them automatically.

See also

On this page