IdempotencyOptions
Defined in: src/http/cache/IdempotencyKey.ts:28
Idempotency-key middleware. Implements the Stripe / Adyen pattern:
clients send an Idempotency-Key header on retryable requests
(typically POST), and the server records the first response under
that key so subsequent requests with the same key replay the same
outcome.
Three states for a given key:
- Absent — handler runs; the (status, headers, body) tuple is
cached under the key for
ttlMs(default 24h). - In-flight — another worker is currently processing this key.
We respond
409 Conflictso the client retries later. - Completed — replay the cached response verbatim.
Storage is JSON-encoded — bodies that are Uint8Array are base64’d
so the round-trip preserves bytes.
Usage:
const dedup = idempotent({ cache: ext.cache(), ttlMs: 24 * 60 * 60_000 }); route(post(‘/payments’, dedup(handler)));
Properties
Section titled “Properties”
readonlycache:Cache
Defined in: src/http/cache/IdempotencyKey.ts:29
headerName?
Section titled “headerName?”
readonlyoptionalheaderName?:string
Defined in: src/http/cache/IdempotencyKey.ts:37
Header to read the idempotency key from. Default: 'idempotency-key'
(the standard). Header names are matched case-insensitively against
the req.headers map (which holds them lower-cased).
keyPrefix?
Section titled “keyPrefix?”
readonlyoptionalkeyPrefix?:string
Defined in: src/http/cache/IdempotencyKey.ts:41
Cache-key namespace. Default: 'idem:'.
missingHeader?
Section titled “missingHeader?”
readonlyoptionalmissingHeader?:"reject"|"pass-through"
Defined in: src/http/cache/IdempotencyKey.ts:48
What to do when the request lacks the header. Default: 'reject'
(respond 400). Setting 'pass-through' runs the handler unchanged
— useful when only some clients use idempotency and you don’t want
to break the others.
ttlMs?
Section titled “ttlMs?”
readonlyoptionalttlMs?:number
Defined in: src/http/cache/IdempotencyKey.ts:31
How long to remember responses. Default: 24 hours.