Skip to content

basalt / fastify/src / idempotencyPlugin

Function: idempotencyPlugin() ​

> idempotencyPlugin(options?): BasaltPlugin<unknown>

Defined in: fastify/src/idempotency.ts:181

Safe retries for mutating requests: when a client sends an Idempotency-Key, the first response is cached and replayed for any repeat with the same key — so a network retry never charges a card or creates a duplicate twice.

  • A repeat while the first is still in-flight → 409 IDEMPOTENCY_CONFLICT.
  • Responses >= 500 are not cached, so genuine failures stay retryable.
  • Keys are scoped by caller credentials (credentialHeaders), tenant (x-tenant-id, host), method and route, and stored as a SHA-256 hash.
  • Requests without credentials are not cached unless allowAnonymous: true.
  • Keys longer than 255 characters → 400 IDEMPOTENCY_KEY_INVALID.

Parameters ​

options? ​

IdempotencyPluginOptions = {}

Returns ​

BasaltPlugin<unknown>

Released under the MIT License.