Advertisement
Beginner ASP.NET Core, Controllers vs Minimal APIs

What is the fundamental structural difference between controller-based APIs (MVC) and minimal APIs in ASP.NET Core?

Short answer

Controller-based APIs organize endpoints as methods within controller classes (inheriting ControllerBase), using attributes ([HttpGet], [Route]) to define routes, relying on the MVC framework's action invocation pipeline.

Save ASP.NET Core mock interview
Advertisement
AModel answer
Controller-based APIs organize endpoints as methods within controller classes (inheriting ControllerBase), using attributes ([HttpGet], [Route]) to define routes, relying on the MVC framework's action invocation pipeline. Minimal APIs define endpoints as direct lambda or method group registrations via app.MapGet/MapPost/etc. directly in Program.cs (or organized into extension methods), without requiring a full controller class, filters pipeline, or the MVC framework's heavier abstractions.
// Controller-based
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase {
    [HttpGet("{id}")]
    public IActionResult Get(int id) => Ok(_service.GetById(id));
}

// Minimal API equivalent
app.MapGet("/api/products/{id}", (int id, IProductService service) => service.GetById(id));
Real-world example
A team building a small, focused microservice with only five endpoints chooses minimal APIs for their reduced ceremony, while a large, complex API with dozens of related endpoints and shared cross-cutting filter logic sticks with controllers.
Likely follow-ups
  • What performance difference exists between the two approaches?
  • Can you mix both controllers and minimal APIs in the same project?
Related topics