GuidesAuthoring & composition
stitch()
Declare an endpoint and get back a typed, callable function — the core authoring move.
Reach for stitch() to declare a single HTTP call once and get back a typed,
callable function — it is the core authoring move that every other feature
layers onto.
Example
Pass a string when the URL is all you need; pass a config object when you want a
baseUrl, a parameterized path, or a non-GET method. The generic types the
awaited value.
import { } from 'stitchapi';
// String form — the string becomes the path; a full URL is fine.
const = <{ : number; : string }[]>(
'https://api.example.com/users',
);
// Config form — baseUrl + a {param} slot; method defaults to GET.
const = <{ : number; : string }>({
: 'https://api.example.com',
: '/users/{id}',
: 'POST',
});
const = await ();
const = await ({ : { : 1 } });Options
The handful of fields that shape every stitch:
baseUrl+path— the request target.pathmay contain{param}slots and a?querystring; in string form the whole string becomespath.method— the HTTP verb. Defaults toGET.- The input object —
params,query,headers, andbodyall travel in oneStitchInputyou pass at call time:await createUser({ params: { id: 1 } }). - The generic —
stitch<T>(...)types the awaited valueT.
Auth, retry, and validation are configured on the same config object but documented in their own guides — see below — so there is one source of truth per feature.
For every field and its default, see Reference → stitch() and Reference → Config types.