Skip to main content
InterviewHubPRO
Section Overview
Q36

Question 36 of 50

Part 3: Distributed Systems, Kestrel Internals & Scalability (25 - 35)

72%
ASP.NET Core & Web API (50 Qs)•Part 3: Distributed Systems, Kestrel Internals & Scalability (25 - 35)

Minimal APIs vs Controller-Based APIs in ASP.NET Core.

senior LevelCode ExampleSystem DesignHTTP & REST APIs

In Simple Words:

  • Controllers ([ApiController]): Traditional approach. Uses reflection, model binding filters, and attribute routing. Organizes code in distinct controller classes.
  • Minimal APIs (app.MapGet(...)): Introduced in .NET 6/7. Eliminates controller boilerplate and reflection overhead. Endpoints map directly to lambda expressions, improving startup performance and delivering up to 30% higher requests per second.
  • Endpoint Filters (AddEndpointFilter): Intercepts requests on Minimal APIs for validation, logging, and metrics without creating complex controller action filters.
csharp
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/api/users/{id}", async (int id, IUserService userService) =>
{
    var user = await userService.GetByIdAsync(id);
    return user is not null ? Results.Ok(user) : Results.NotFound();
}).AddEndpointFilter(async (context, next) => {
    // Reusable Minimal API filter
    return await next(context);
});

app.Run();