Minimal APIs define HTTP endpoints with less ceremony than controller-based APIs. Route mappings and handlers can live in Program.cs, avoiding a separate controller class and often producing a smaller, more readable codebase. section 1.2.4 section 1.3
Use the approach when its simplicity matches the feature:
- Map each route with methods such as MapGet and MapDelete, supplying a path and handler. section 1.2.4
- Keep one-line implementations in Program.cs, but move substantial business logic into other classes. section 1.2.4
- Prefer minimal APIs for simple web APIs and microservices; retain controllers when complex data operations make their structure more convenient. section 1.3 section 2.4.5
Mapping a board-game endpoint
A small endpoint can return board-game data directly: app.MapGet("/BoardGames", () => new[] { new BoardGame { Id = 1, Name = "Axis & Allies", Year = 1981 }, new BoardGame { Id = 2, Name = "Citadels", Year = 2000 }, new BoardGame { Id = 3, Name = "Terraforming Mars", Year = 2016 } }); The same behavior could be supplied by a controller, but the minimal form keeps the route and response together. section 2.4.5
// app.MapControllers(); #1
app.MapGet("/api/Sample", #2
() => "TODO: return all items"); #2
app.MapGet("/api/Sample/{id}", #2
(int id) => $"TODO: return the item with id #{id}"); #2
app.MapDelete("/api/Sample/{id}", #2
(int id) => $"TODO: delete the item with id #{id}"); #2
Inspect the route mappings for collection, item, and delete endpoints, including a route parameter bound to an integer handler argument. section 1.2.4
Minimal API endpoints do not automatically receive controller-based Swagger grouping. Add explicit tags when related endpoints should appear under a named group such as Auth. section 11.2.7


