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 },}));Ready. No request sent.
Result
Choose Run to see the response.
Event log
No events yet.
What to notice
Section titled “What to notice”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.