Minimal APIs (.NET 10)
Core Principles
- Minimal APIs are the default — Use controllers only when migrating legacy code. Minimal APIs are lighter, faster, and compose well with any architecture style.
- Group endpoints with
MapGroup— Never scatter individualMapGet/MapPostcalls inProgram.cs. Group related endpoints together. - Use
TypedResultsfor OpenAPI —TypedResults.Ok(value)gives you compile-time type safety AND correct OpenAPI documentation.Results.Ok(value)does not. - Metadata over comments — Use
.WithName(),.WithTags(),.WithSummary()to document endpoints. The metadata feeds into OpenAPI specs.
Patterns
Endpoint Group Auto-Discovery (Required Pattern)
Every endpoint group lives in its own file and implements IEndpointGroup. A single app.MapEndpoints() call in Program.cs discovers and registers all groups automatically. Program.cs never changes when you add new endpoint groups.
TypedResults for Type-Safe Responses
TypedResults provides compile-time guarantees and automatic OpenAPI schema generation.
Parameter Binding
.NET 10 minimal APIs bind parameters from route, query, header, body, and DI automatically.
Endpoint Filters
Filters are the minimal API equivalent of action filters. Use them for cross-cutting concerns like validation, logging, and idempotency checks.
The canonical ValidationFilter<TRequest> implementation (FluentValidation, resolves the validator from DI and skips gracefully when none is registered) lives in the error-handling skill — use that one, don't re-implement it per project.
OpenAPI / Swagger Configuration
.NET 10 has built-in OpenAPI support. Use it instead of Swashbuckle.
