Under heavy development
StitchAPI
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. path may contain {param} slots and a ?query string; in string form the whole string becomes path.
  • method — the HTTP verb. Defaults to GET.
  • The input objectparams, query, headers, and body all travel in one StitchInput you pass at call time: await createUser({ params: { id: 1 } }).
  • The genericstitch<T>(...) types the awaited value T.

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.

See also

On this page