Retries

This demo endpoint fails twice before succeeding. Its attempt header is a demo protocol, not a requirement for your API.

import { Http, envelope } from "fetchzen";
let attempt = 0;
const api = Http.create(`${location.origin}/api/examples/`, {
cache: false, secure: false, preset: envelope,
fetch: (input, init) => {
const headers = new Headers(init?.headers);
headers.set("X-Demo-Attempt", String(++attempt));
return globalThis.fetch(input, { ...init, headers });
},
});
console.log(await api.get("retry", {
retry: { attempts: 2, respectRetryAfter: true },
}));
Try this requestRetry / transport attempts

Only Run sends a request to this site's demo API. Use synthetic data only; do not send secrets or personal files. Uploads are counted, not stored.

Ready. No request sent.

Result

Choose Run to see the response.
Event log
No events yet.

Two retries allow three sends. Attempts 1 and 2 return 503 with Retry-After: 0. Request hooks run once per logical request; the transport runs per send. Consider idempotency before retrying writes.

Next: hooks or resilience.