Skip to content

Commit 85ec9f7

Browse files
feat: Sps-Idempotency-Key Header Proposal (#98)
Supporting Reusable Model Draft: SPSCommerce/sps-api-design#161 --------- Signed-off-by: Nicholas Perkins <[email protected]> Co-authored-by: Travis Gosselin <[email protected]> Co-authored-by: travisgosselin <[email protected]>
1 parent b4aa155 commit 85ec9f7

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

standards/request-response.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,6 @@ Access-Control-Allow-Origin: *
442442
Access-Control-Allow-Methods: *
443443
```
444444

445-
<hr />
446-
447-
```note
448-
**KEEP AN EYE ON IT**: The [Idempotency-Key Request header](https://tools.ietf.org/id/draft-idempotency-header-01.html) is in an experimental state but getting lots of attention as a pattern of making fault-tolerant resilient requests for traditionally non-idempotent methods like `POST`.
449-
```
450-
451445
### Custom Headers
452446

453447
- Custom Headers **MAY** be used and created as necessary.
@@ -494,6 +488,8 @@ The usage of non-standard headers is not considered custom headers. For example,
494488
Sps-Cors-Error: bad origin
495489
```
496490

491+
<hr />
492+
497493
#### Sps-Execution-Context
498494

499495
**Type**: Both
@@ -527,6 +523,36 @@ Sps-Execution-Context: // values must be at least a character l
527523
Sps-Execution-Context: 1 // valid, but SHOULD be human-readable.
528524
```
529525

526+
<hr />
527+
528+
#### Sps-Idempotency-Key
529+
530+
**Type**: Request
531+
532+
**Support**: OPTIONAL
533+
534+
**Description**: An idempotency key is a unique value generated by the client which the resource server uses to recognize subsequent retries of the same request. The HTTP `Idempotency-Key` request header field can be used to carry an "idempotency key" to make non-idempotent HTTP methods such as POST or PATCH fault-tolerant (related to expired RFC for [Idempotency HTTP Header Field](https://datatracker.ietf.org/doc/html/draft-idempotency-header-01)). An API must persist the Idempotency-Key in a stateful way to manage idempotency. It is common to include the idempotency key as part of the primary key or as a secondary index for the resource.
535+
536+
- The header value **MUST NOT** be shorter than 20 characters or longer than 255.
537+
- The header value **MUST** not be used for `GET` requests.
538+
- The header value **MUST** follow this regex format: `[a-z0-9-]{20,255}`.
539+
- An API **MUST** return a `400` status code when the header value is in an invalid format with an appropriate error message.
540+
- If an action is idempotent, an API **MUST** return a `2xx` status code on conflict.
541+
- If an action is not idempotent, an API **MUST** return a `409` status code on conflict.
542+
- An API **MAY** treat this as the final primary ID of the resource or as part of the ID.
543+
- The header value **SHOULD** typically be a V4 UUID as a string or another random string with enough entropy to avoid collisions.
544+
- The header value **MUST** be generated by the client or client library.
545+
546+
```
547+
// CORRECT
548+
Sps-Idempotency-Key: d4f885c5-2196-49c0-ba69-bc70008585ad
549+
Sps-Idempotency-Key: d4f885c5-2196-49c0-ba69-bc70008585ad-custom
550+
551+
// INCORRECT
552+
Sps-Idempotency-Key: a // not enough entropy, and below minimum character length.
553+
Sps-Idempotency-Key: KG5Lxw!@#$&*()FBepaKHyUD // non-url-safe special characters can be limiting for usage or later reference
554+
```
555+
530556
## MIME Types
531557

532558
### Standard MIME Types

0 commit comments

Comments
 (0)