Skip to content

IETF Spec Compliance

The idempot-js library implements draft-ietf-httpapi-idempotency-key-header-07, the IETF standard for the Idempotency-Key HTTP header.

This document details how the library complies with each requirement in the specification.

Implemented Requirements

MUST Requirements (Required)

RequirementSectionImplementation
Idempotency-Key as String2.1✅ Header value extracted as string
Unique idempotency keys2.2✅ Key stored with request fingerprint to ensure uniqueness
Identify idempotency key from header2.5.2✅ Parses Idempotency-Key header (configurable via headerName option)
Generate idempotency fingerprint2.5.2✅ SHA-256 hash of method + path + body
Enforce idempotency2.6✅ Returns cached response for duplicate requests
RequirementSectionImplementation
Use UUID or random identifier2.2✅ Library doesn't generate keys (client responsibility), but validates format
Publish expiration policy2.3✅ Configurable via ttlMs option
Return 400 if key missing2.7✅ Optional via required: true option
Return 422 if key reused with different payload2.7✅ Returns 422 with problem details when fingerprint mismatch detected
Return 409 for concurrent requests2.7✅ Returns 409 Conflict when original request still processing

MAY Requirements (Optional)

RequirementSectionImplementation
Idempotency fingerprint2.4✅ SHA-256 hash of method + path + body (configurable via hashAlgorithm option)
Time-based expiry2.3✅ Configurable via ttlMs option, defaults to 24 hours

Error Responses

The library follows the spec's error handling recommendations:

ScenarioStatus CodeResponse
Missing Idempotency-Key (when required)400Problem Details JSON with link to documentation
Key reused with different payload422Problem Details JSON with "Idempotency-Key is already used"
Concurrent request (still processing)409Problem Details JSON with "request is outstanding"

Configuration Options

The library provides flexibility to match your API's idempotency requirements:

javascript
import { idempotency } from "@idempot/express-middleware";

app.use(idempotency({
  // Storage backend (required)
  store: new RedisStore({ url: process.env.REDIS_URL }),
  
  // Header name (default: "Idempotency-Key")
  headerName: "Idempotency-Key",
  
  // Whether key is required (default: false)
  required: false,
  
  // Time-to-live in milliseconds (default: 86400000 = 24h)
  ttlMs: 86400000,
  
  // Fields to exclude from fingerprint
  excludeFields: ["timestamp"],
  
  // Hash algorithm (default: "xxhash64", also supports "sha256")
  hashAlgorithm: "xxhash64"
}));

What's Not Covered

The spec leaves some things to the application layer:

  • Key format: The spec recommends UUIDs but doesn't mandate them. The library accepts any string value.
  • Store implementation: The spec doesn't prescribe how to store idempotency records. We provide multiple store implementations (Redis, PostgreSQL, MySQL, SQLite, Bun SQL).
  • Key generation: The spec says clients should generate keys. We don't generate keys—clients provide them.

Compliance Status

Full compliance with draft-ietf-httpapi-idempotency-key-header-07

All MUST and SHOULD requirements are implemented. The library gives you the flexibility to choose which optional features to enable based on your API's needs.