Guides & Recipes — Idempotency
Recommended recipes for idempotent HTTP endpoints and safe response caching.
Recipe 1: Protecting Minimal API Endpoints with WithIdempotency
Section titled “Recipe 1: Protecting Minimal API Endpoints with WithIdempotency”In v2.0.0, endpoint [Idempotent] metadata takes precedence (ADR-018) and malformed Idempotency-Key headers return HTTP 400 Bad Request (RFC 9110) instead of 500:
using EricksonLopez.Idempotency.AspNetCore;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Http;
namespace Example.IdempotencyRecipes;
public static class PaymentEndpoints{ public static void MapPayments(WebApplication app) { app.MapPost("/payments/charge", static () => Results.Ok(new { Status = "Charged" })) .WithIdempotency(); }}Recipe 2: Hardening ResponseHeadersBlocklist
Section titled “Recipe 2: Hardening ResponseHeadersBlocklist”v2.0.0 strips Set-Cookie, Authorization, and related sensitive headers by default (SEC-001). Append any custom internal auth or correlation headers to options.ResponseHeadersBlocklist inside AddIdempotencyCore(...) so cached replays never leak session credentials across clients.