Minimal APIs map routes to lambdas or delegates in Program.cs—less ceremony than controllers for small services, prototypes, and micro-endpoints.
Example
var app = WebApplication.CreateBuilder(args).Build();
app.MapGet("/hello", () => Results.Ok(new { message = "Hello" }));
app.MapGet("/products/{id:int}", async (int id, AppDbContext db) =>
await db.Products.FindAsync(id) is { } p
? Results.Ok(p)
: Results.NotFound());
app.Run();
Minimal vs controllers
- Minimal — fast to write, great for small APIs and cloud functions style
- Controllers — better for large APIs with filters, versioning, and complex conventions
Important interview questions and answers
- Q: Can minimal APIs use DI?
A: Yes—parameters likeAppDbContext dbresolve from the container automatically. - Q: When not use minimal APIs?
A: Large teams needing strict layering, many cross-cutting filters, or MVC + API mixed conventions may prefer controllers.
Self-check
- Where are minimal API routes typically defined?
- How does a handler return 404?