minimal-api
Skill853 starsChanged yesterdayMITView on GitHub
Minimal APIs on .NET 10, the default for HTTP endpoints: one IEndpoint per feature with MapModules/MapEndpoints discovery, TypedResults, endpoint filters, parameter binding, rate limiting, API versioning (Asp.Versioning). Use for "endpoint", "MapGet", "MapGroup", "IEndpoint", "rate limiting", "API versioning". Do NOT use for OpenAPI documents or Scalar (use openapi) or module and project layout (use modular-slices).
2 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- codewithmukesh/dotnet-claude-kitword for word, first seen Nov 8, 2026
- Resgrid/Coreedited, first seen Oct 8, 2026
Other versions2 projects use a version of this.
Word for word · 1
- codewithmukesh/dotnet-claude-kit★ 853100% same
Edited · 1
- Resgrid/Core★ 23923% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository38 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- .opencode/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/dotnet-rules.mdCursor rule
- architecture-advisorSkill
- aspireSkill
- authenticationSkill
- build-fixSkill
- cachingSkill
- ci-cdSkill
- code-reviewSkill
- configurationSkill
- console-cliSkill
- dependency-injectionSkill
- desktop-mvvmSkill
- de-sloppifySkill
- dockerSkill
- doctorSkill
- dotnet-initSkill
- ef-coreSkill
- error-handlingSkill
- instinct-systemSkill
- loggingSkill
- messagingSkill
- migrateSkill
- modern-csharpSkill
- modular-slicesSkill
- native-aotSkill
- openapiSkill
- opentelemetrySkill
- resilienceSkill
- scaffoldSkill
- specSkill
- tddSkill
- testingSkill
- verifySkill
- wrap-upSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Minimal APIs are the default: Use controllers only when migrating legacy code.
≈ “Common” is an estimate: at least 1 in 5 of the 383,637 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.
- One
IEndpointper feature, discovered by convention. Each feature folder has one endpoint class.Program.cscalls one discovery method (app.MapModules()in a modular app,app.MapEndpoints()in a single project) and never changes when features are added. - Return
TypedResultsunions.Results<Created<T>, ProblemHttpResult>gives compile-time checking and correct OpenAPI documentation without.Produces()calls.Results.Ok(value)andIResultgive neither. - Metadata over comments.
.WithName(),.WithSummary()and XML comments on request/response records feed the OpenAPI document.
Patterns
One IEndpoint per Feature (Required Pattern)
The endpoint is a thin adapter: route, authorization, OpenAPI text, and a call to the feature's handler. The full interfaces (IEndpoint, IHandler, IModule) and discovery code are in skills/modular-slices/references/building-blocks.md.
public interface IEndpoint
{
void Map(IEndpointRouteBuilder endpoints);
}// Features/PlaceOrder/PlaceOrderEndpoint.cs
internal sealed class PlaceOrderEndpoint : IEndpoint
{
public void Map(IEndpointRouteBuilder endpoints) =>
endpoints.MapPost("/", HandleAsync)
.RequirePermission(OrdersPermissions.Manage)
.WithName("PlaceOrder")
.WithSummary("Places an order");
private static Task<Results<Created<OrderResponse>, ProblemHttpResult>> HandleAsync(
PlaceOrderRequest request, PlaceOrderHandler handler, CancellationToken ct) =>
handler.HandleAsync(request, ct);
}In a modular app, MapModules() maps every module's endpoints under /api/v1/{module}, tags them with the module name, and adds the validation filter, so the route above is relative to the module group:
// Program.cs (modular): never changes when features are added
builder.AddModule<CatalogModule>();
builder.AddModule<OrdersModule>();
var app = builder.Build();
app.MapModules();In a single-project app, one scan does the same job:
public static IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder app)
{
var api = app.MapGroup("/api")
.AddEndpointFilterFactory(RequestValidation.Create)
.ProducesValidationProblem();
foreach (var type in typeof(Program).Assembly.GetTypes()
.Where(t => t is { IsClass: true, IsAbstract: false } && typeof(IEndpoint).IsAssignableFrom(t))
.OrderBy(t => t.FullName, StringComparer.Ordinal))
((IEndpoint)Activator.CreateInstance(type)!).Map(api);
return app;
}Endpoints are sorted by name so routes and the OpenAPI document come out in the same order on every build.
TypedResults Unions for Type-Safe Responses
The handler's return type is the endpoint's HTTP contract. Errors are ProblemDetails with a stable code built by the Problems helper (see the error-handling skill).
internal sealed class GetOrderHandler(OrdersDbContext db) : IHandler
{
public async Task<Results<Ok<OrderResponse>, ProblemHttpResult>> HandleAsync(Guid id, CancellationToken ct)
{
var order = await db.Orders.AsNoTracking()
.Where(o => o.Id == id)
.Select(o => new OrderResponse(o.Id, o.ProductId, o.Quantity, o.Total, o.PlacedAt))
.FirstOrDefaultAsync(ct);
return order is null ? Problems.NotFound() : TypedResults.Ok(order);
}
}Returning a result type that is not in the union is a compile error, and OpenAPI documents 200 and the problem response automatically.
Parameter Binding
.NET 10 minimal APIs bind parameters from route, query, header, body, and DI automatically.
// Route parameters
endpoints.MapGet("/{id:guid}", (Guid id, GetOrderHandler handler, CancellationToken ct) => handler.HandleAsync(id, ct));
// Query parameters (nullable = optional)
endpoints.MapGet("/", (int page, int? pageSize, string? status) => ...);
// Complex query parameters with [AsParameters]
public sealed record ListOrdersQuery(int Page = 1, int PageSize = 20, string? Status = null);
endpoints.MapGet("/", ([AsParameters] ListOrdersQuery query, ListOrdersHandler handler, CancellationToken ct) => ...);
// Header binding (FromHeader needs using Microsoft.AspNetCore.Mvc;)
endpoints.MapGet("/", ([FromHeader(Name = "X-Correlation-Id")] string? correlationId) => ...);
// DI services (including handlers) are resolved without an attribute
endpoints.MapPost("/", (PlaceOrderRequest request, PlaceOrderHandler handler, CancellationToken ct) => ...);Endpoint Filters
Filters are the minimal API equivalent of action filters. Use them for cross-cutting concerns like validation, logging, and idempotency checks.
Validation uses one filter factory on the top-level group (RequestValidation.Create, in the modular-slices building blocks). It runs the FluentValidation validator of any parameter that has one and returns a 400 ValidationProblem with code: validation-failed. Endpoints never add validation filters one by one, and endpoints without validated parameters get no filter at all.
// Once, on the top-level group (MapModules and MapEndpoints already do this)
var api = app.MapGroup("/api/v1")
.AddEndpointFilterFactory(RequestValidation.Create)
.ProducesValidationProblem();
// Other filters on a single endpoint
endpoints.MapPost("/", HandleAsync).AddEndpointFilter<IdempotencyFilter>();OpenAPI Configuration
.NET 10 has built-in OpenAPI support. Use it instead of Swashbuckle (see the openapi skill).
builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
app.MapOpenApi();
app.MapModules(); // or app.MapEndpoints() in a single project
// Inside an IEndpoint: the union supplies the response types; add names and text
endpoints.MapPost("/", HandleAsync)
.WithName("PlaceOrder")
.WithSummary("Places an order")
.WithDescription("Places an order for one product. Fails with orders.product-not-found if the product is unknown.");Rate Limiting
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("api", opt =>
{
opt.PermitLimit = 100;
opt.Window = TimeSpan.FromMinutes(1);
});
});
// Inside an IEndpoint.Map method
endpoints.MapPost("/", HandleAsync).RequireRateLimiting("api");Output Caching
builder.Services.AddOutputCache(options =>
{
options.AddBasePolicy(policy => policy.Expire(TimeSpan.FromMinutes(5)));
options.AddPolicy("ByIdCache", policy => policy
.Expire(TimeSpan.FromMinutes(10))
.SetVaryByRouteValue("id"));
});
endpoints.MapGet("/{id:guid}", HandleAsync).CacheOutput("ByIdCache");API Versioning
Version from day one: URL segment (/api/v1/...) is the default, a breaking change means a new version, and features opt into versions with .MapToApiVersion(2, 0). Setup, version sets with IEndpoint, deprecation and anti-patterns are in references/api-versioning.md.
Anti-patterns
Don't Put Endpoints in Program.cs
// BAD: endpoints scattered in Program.cs
app.MapGet("/orders", async (AppDbContext db) => await db.Orders.ToListAsync());
app.MapPost("/orders", async (Order order, AppDbContext db) => { /* ... */ });
// ALSO BAD: manual wiring that grows with every feature
app.MapGroup("/api/orders").WithTags("Orders").MapOrderEndpoints();
app.MapGroup("/api/products").WithTags("Products").MapProductEndpoints();
// GOOD: auto-discovered, Program.cs never changes
app.MapModules(); // every IEndpoint in every moduleDon't Put a Whole Resource in One Endpoint Class
// BAD: every order operation edits this file
public sealed class OrderEndpoints : IEndpointGroup
{
public void Map(IEndpointRouteBuilder app) { /* MapPost, MapGet, MapPut, MapDelete, cancel... */ }
}
// GOOD: one IEndpoint per feature folder
internal sealed class CancelOrderEndpoint : IEndpoint
{
public void Map(IEndpointRouteBuilder endpoints) =>
endpoints.MapPost("/{id:guid}/cancel", HandleAsync).RequirePermission(OrdersPermissions.Manage);
private static Task<Results<Ok<OrderResponse>, ProblemHttpResult>> HandleAsync(
Guid id, CancelOrderRequest request, CancelOrderHandler handler, CancellationToken ct) =>
handler.HandleAsync(id, request, ct);
}Don't Use Untyped Results
// BAD: IResult hides the status codes from the compiler and from OpenAPI
private static async Task<IResult> GetOrder(Guid id, OrdersDbContext db)
{
var order = await db.Orders.FindAsync(id);
return order is not null ? Results.Ok(order) : Results.NotFound();
}
// GOOD: TypedResults union, ProblemDetails for the failure
private static async Task<Results<Ok<OrderResponse>, ProblemHttpResult>> GetOrder(
Guid id, OrdersDbContext db, CancellationToken ct)
{
var order = await db.Orders.AsNoTracking()
.Where(o => o.Id == id)
.Select(o => new OrderResponse(o.Id, o.ProductId, o.Quantity, o.Total, o.PlacedAt))
.FirstOrDefaultAsync(ct);
return order is not null ? TypedResults.Ok(order) : Problems.NotFound();
}Don't Return Domain Entities Directly
// BAD: leaks internal structure, can't evolve independently
return TypedResults.Ok(await db.Orders.Include(o => o.Items).FirstOrDefaultAsync(o => o.Id == id, ct));
// GOOD: project to a response record
var order = await db.Orders
.Where(o => o.Id == id)
.Select(o => new OrderResponse(o.Id, o.ProductId, o.Quantity, o.Total, o.PlacedAt))
.FirstOrDefaultAsync(ct);Decision Guide
| Scenario | Recommendation |
| New HTTP API with several business areas | IEndpoint per feature inside modules + app.MapModules() (modular-slices) |
| Small single-area API | IEndpoint per feature + app.MapEndpoints() (architecture-advisor, references/vertical-slice.md) |
| Return type | TypedResults union, errors as ProblemHttpResult with a stable code |
| Existing MVC project | Keep controllers, migrate incrementally |
Existing IEndpointGroup codebase | Keep it; do not mix both styles in one project |
| OpenAPI documentation | TypedResults unions + .WithName() + .WithSummary() |
| Request validation | One FluentValidation filter factory on the top-level group |
| Authentication/authorization | .RequirePermission(...) or .RequireAuthorization(...) on every endpoint, plus a fallback policy |
| Rate limiting | AddRateLimiter + .RequireRateLimiting() |
| Response caching | AddOutputCache + .CacheOutput() |
| Evolving the API with breaking changes | New API version; see references/api-versioning.md |
| Complex model binding | [AsParameters] with a record type |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

