Skip to main content

Module idempotency

Module idempotency 

Source
Expand description

IdempotencyKey newtype for safe retry of non-idempotent HTTP methods.

An idempotency key is an opaque string (or UUID) that a client sends once per logical operation. The server uses it to detect duplicate requests and return the cached outcome instead of re-executing the operation.

§Constraints

  • Length: 1–255 characters (inclusive).
  • Characters: printable ASCII only (0x200x7E), i.e. no control characters or non-ASCII bytes.

§Example

use api_bones::idempotency::IdempotencyKey;

// From an arbitrary string
let key = IdempotencyKey::new("my-op-abc123").unwrap();
assert_eq!(key.as_str(), "my-op-abc123");

// From a freshly generated UUID
let key = IdempotencyKey::from_uuid();
assert!(!key.as_str().is_empty());

Structs§

IdempotencyKey
A validated idempotency key for safe POST/PATCH retry semantics.

Enums§

IdempotencyKeyError
Errors that can occur when constructing an IdempotencyKey.