Under heavy development
StitchAPI

Quickstart

Declare your first stitch from one endpoint and call it as a typed function in five minutes.

In about five minutes you will declare your first stitch from a single endpoint and call it as a typed, async function — no spec, no codegen, no server. This page assumes the package is already installed; if not, start with Installation.

Declare a stitch

The smallest stitch is a URL. Pass it to stitch() as a string and you get back a callable — the string sets the path:

import {  } from 'stitchapi';

const  = ('https://api.example.com/users');

Call it as a typed function

The returned value is a function. Call it and await the result — await is sugar that consumes the underlying stream and returns the final, validated value (a GET with parsed JSON here):

import {  } from 'stitchapi';

const  = ('https://api.example.com/users');

const  = await ();

Add path params and query

Use {param} slots in the path. Params, query, headers, and body all travel in a single input object, so a path param goes under params and query keys under query:

import {  } from 'stitchapi';

const  = ('https://api.example.com/users/{id}');

await ({ : { : 1 }, : { : 'roles' } });
// → GET https://api.example.com/users/1?expand=roles

Type the result

Pass a type argument to stitch<T>() and the awaited value is typed as T, with no extra dependency:

import {  } from 'stitchapi';

const  = <{ : number; : string }>(
    'https://api.example.com/users/{id}',
);

const  = await ({ : { : 1 } });

The generic gives you compile-time types only. To also validate the response at runtime — and catch a vendor silently renaming a field — bring a Standard Schema validator as the output; see Validation.

Observe the event stream

A stitch does not return Promise<bytes> — it yields a typed event stream, and await simply consumes it for you. Call .stream() instead to watch progress, retries, and drift as they happen:

import {  } from 'stitchapi';

const  = ('https://api.example.com/users');

for await (const  of .()) {
    if (. === 'result') .(.);
}

The event stream concept covers every event type in depth.

Next steps

On this page