Under heavy development
StitchAPI

Loop a cursor API into one array

Follow nextCursor across every page and aggregate the items — no manual while-loop, cursor bookkeeping, or concat.

Task

An endpoint returns one page at a time behind a cursor. You want every item in a single array — without writing the while loop, the cursor bookkeeping, and the concat by hand.

Example

One way: declare how to find the next page and which array to collect, and await once.

import {  } from 'stitchapi';

const  = ({
    : 'https://api.example.com',
    : '/users',
    : {
        : () => {
            const  = ( as { ?: string }).;
            return  ? { : {  } } : ;
        },
        : () => ( as { : unknown[] }).,
        : 20,
    },
});

// One await follows every page and returns the aggregated items.
const  = (await ()) as unknown[];

How it works

next(prevBody) reads the cursor off the previous page's raw body and returns the input for the next page, merged over the original call — set only what changes. Return undefined to stop. items selects the array to aggregate from each page (after unwrap). max caps the page count as a safety net (default 50). Auth, retry, and throttle apply per page, not once for the whole run. Without an output schema the aggregated result is typed unknown[], hence the cast — add a schema to type the rows.

See also

On this page