Skip to main content

Crate nestrs_idempotency

Crate nestrs_idempotency 

Source
Expand description

NestJS @nestjs/idempotency analogue — Idempotency-Key request deduplication.

§Behavior

  1. Missing key → pass through (or 400 if IdempotencyOptions::required).
  2. Completed key → replay stored status/body with header idempotency-replayed: true.
  3. In-flight key → 409 (IDEMPOTENCY_IN_FLIGHT).
  4. First writer → run handler, then IdempotencyStore::complete.

§Security

Always set IdempotencyOptions::scope to the authenticated principal so tenants cannot replay another user’s response. Prefer Redis TTL in multi-instance deploys (cache-redis).

§Middleware

ⓘ
use axum::middleware::from_fn_with_state;
use nestrs_idempotency::{idempotency_middleware, IdempotencyOptions};
use std::sync::Arc;

let opts = Arc::new(IdempotencyOptions::default());
let router = router.layer(from_fn_with_state(opts, idempotency_middleware));

Umbrella feature: nestrs / idempotency → nestrs::idempotency.

Structs§

DynamicModule
Runtime-composed module unit for conditional imports (feature flags, env switches, plugins).
IdempotencyModule
IdempotencyOptions
IdempotencyRecord
InMemoryIdempotencyStore
ProviderRegistry

Traits§

IdempotencyStore
Injectable
Application service or provider type constructed through the DI container.

Functions§

idempotency_middleware
Axum middleware: replay stored responses for repeated Idempotency-Key values.