Under heavy development
StitchAPI

Make a flaky call succeed on its own

Add retry with backoff so transient 429s and 5xxs recover without your code noticing.

Task

An API you depend on returns the occasional 429 or 503 that clears on its own. You do not want every call site wrapped in a try/catch and a sleep.

Example

One way: declare a retry policy on the stitch and let the caller just await the value.

import {  } from 'stitchapi';

const  = ({
    : 'https://api.example.com',
    : '/users/{id}',
    : {
        : 3,
        : [429, 503],
        : 'expo-jitter',
        : true,
    },
});

// A transient 429 or 503 is retried up to twice; the caller just gets the value.
const  = await ({ : { : 1 } });

How it works

attempts is the total number of tries including the first, so 3 means up to two retries. on is the set of status codes that trigger a retry. backoff: 'expo-jitter' doubles the wait each attempt and spreads it randomly to avoid thundering herds. respectRetryAfter honors a Retry-After header when the server tells you when to come back. Each retry rides the event stream as a progress event (phase retry), so you can watch it happen. When the dependency is not just flaky but failing, compose retry with a timeout and circuit breaker.

See also

On this page