DKNet

Protect endpoints and route groups

Part of DKNet.AspCore.Idempotency. Register services as in the overview, then declare protection on a route or group:

using DKNet.AspCore.Idempotency;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIdempotentKey();
var app = builder.Build();
var orders = app.MapGroup("/orders").RequiredIdempotentKey();
orders.MapPost("/", () => Results.Ok());
orders.MapGet("/", () => Results.Ok());
app.MapPost("/single", () => Results.Ok()).RequiredIdempotentKey();
await app.RunAsync();

The group convention matches routed verbs, attaches the filter to covered endpoints, and leaves unmatched endpoints unchanged.

The group overload defaults to POST. Pass explicit verbs, such as RequiredIdempotentKey("POST", "DELETE"), to cover others. Matching uses routed HTTP method metadata, case-insensitively, at endpoint build time; request method-override headers do not change coverage. Nested groups inherit the convention, including endpoints registered before the declaration. A per-request marker prevents double execution when both declarations apply.

⚙️ Configuration reference

Input Type Default Effect
httpMethods params string[] POST Selects the routed verbs covered by a group.

Header and key settings are owned by key validation.

⚠️ Gotchas & limits