.NET 6 introduces “Minimal APIs”, a stripped-down approach to building HTTP APIs without the ceremony of Controllers, Filters, or `Startup.cs`.
Four Lines of Code
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
Parameter Binding
It infers binding from route, query, or body automatically.
app.MapPost("/todos", (Todo todo, MyDbContext db) =>
{
db.Todos.Add(todo);
return Results.Created($"/todos/{todo.Id}", todo);
});
Key Takeaways
- Minimal APIs are **faster** than Controllers (less reflection overhead).
- You can still use DI, Auth, and Validation.
- Great for microservices where you only have 2-3 endpoints.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.