Handles Stripe-compatible idempotency key processing.
Prevents duplicate POST requests from creating duplicate resources by
caching responses keyed by the Idempotency-Key header.
Usage
# In router
plug PaperTiger.Plugs.IdempotencyBehavior
- GET requests - Idempotency keys ignored (safe methods)
- POST with key - Check cache, return cached response if exists
- POST without key - Process normally (not idempotent)
Cache Storage
Responses cached for 24 hours via PaperTiger.Idempotency.
Implementation
This plug only checks the cache. Storing responses happens in resource handlers after successful processing.
Example
# First request with key
POST /v1/customers
Idempotency-Key: abc123
=> Creates customer, stores response
# Duplicate request (network retry)
POST /v1/customers
Idempotency-Key: abc123
=> Returns cached customer (no duplicate created)