View Source IdempotencyPlug (IdempotencyPlug v0.1.2)
Plug that handles Idempotency-Key
HTTP headers.
A single Idempotency-Key
HTTP header is required for POST and PATCH requests.
Handling of requests is based on https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/
request-id
Request ID
The value of the Idempotency-Key
HTTP header is combined with a URI to
produce a unique ID for the request. This will be used to store the response
for first-time requests. The ID is used to fetch this response in all
subsequent requests.
A fingerprint of the request payload is generated and used to ensure the ID is not reused with a different request payload.
error-handling
Error handling
- Concurrent requests will return a
409 Conflict
response. - Mismatch of request payload fingerprint will return
422 Unprocessable Entity
response. - If the first-time request was unexpectedly terminated a
500 Internal Server
is returned.
Cached responses and halted first-time requests, returning an Expires
header in the response.
See IdempotencyPlug.RequestTracker
for more on expiration.
options
Options
:handler
- the handler module to use for building the idempotent id and error response. Defaults toIdempotencyPlug.Handler
. SeeIdempotencyPlug.Handler
for more.:tracker
- the name or pid for theIdempotencyPlug.RequestTracker
GenServer. Defaults toIdempotencyPlug.RequestTracker
.
examples
Examples
plug IdempotencyPlug,
tracker: IdempotencyPlug.RequestTracker,
handler: IdempotencyPlug.Handler