Minimal APIs in .NET: A Modern Alternative to Controllers

Minimal APIs strip the ceremony out of building ASP.NET Core endpoints. This guide covers routing, model binding, TypedResults, route groups, the built-in validation added in .NET 10, and when Minimal APIs make more sense than MVC controllers.

If you learned ASP.NET Core through MVC controllers, Minimal APIs can feel almost too simple the first time you see them, an endpoint that used to take a whole controller class now fits on one line. That simplicity is the point. Minimal APIs, introduced in .NET 6 and matured significantly through .NET 10, are Microsoft’s answer to a real problem: a lot of APIs don’t need the ceremony that MVC controllers were designed for.

Contents

What a Minimal API Actually Looks Like

At its simplest, an entire API can live in Program.cs:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

There’s no controller class, no [HttpGet] attribute, no routing convention to learn app.MapGet, MapPost, MapPut, and MapDelete correspond directly to HTTP verbs, and each one takes a route pattern plus a handler.

Route Parameters and Model Binding

Route values, query strings, headers, and the request body all bind automatically based on the handler’s parameter types:

app.MapGet("/users/{userId}/books/{bookId}",
    (int userId, int bookId) => $"User {userId}, book {bookId}");

app.MapGet("/todos/{id:int}", (int id, TodoDb db) => db.Todos.Find(id));

app.MapPost("/todos", (Todo todo, TodoDb db) =>
{
    db.Todos.Add(todo);
    db.SaveChanges();
    return Results.Created($"/todos/{todo.Id}", todo);
});

Notice TodoDb db in both handlers that’s dependency injection, resolved directly as a parameter, no constructor required. Explicit binding attributes like [FromHeader], [FromBody], and [FromForm] are still available for the cases where the framework can’t infer the source on its own.

The Same Endpoint, Two Ways

The clearest way to see what Minimal APIs remove is to look at the same endpoint written both ways.

Minimal APIs in .NET - before-after

Same behavior – resolve a service from DI, return 404 or 200 – with roughly a third of the code. That difference compounds fast once an API has dozens of endpoints.

Returning Results the Right Way

Minimal APIs support returning plain strings and objects (which get serialized to JSON automatically), but for anything beyond a trivial endpoint, TypedResults is the better choice:

app.MapGet("/products/{id}", async Task<Results<Ok<Product>, NotFound>> (int id, IProductService service) =>
{
    var product = await service.GetByIdAsync(id);
    return product is null ? TypedResults.NotFound() : TypedResults.Ok(product);
});

TypedResults gives you compile-time checking of your possible response types and – importantly – feeds accurate response type information into OpenAPI/Swagger generation, which Results.Ok(...) alone can’t do as reliably.

Keeping Larger APIs Organized: Route Groups

The most common objection to Minimal APIs is “this doesn’t scale past a handful of endpoints.” MapGroup addresses that directly, letting you organize endpoints by resource and share configuration, prefixes, tags, auth requirements, across a whole group:

app.MapGroup("/api/products")
    .MapProductsApi()
    .WithTags("Products")
    .RequireAuthorization();

static RouteGroupBuilder MapProductsApi(this RouteGroupBuilder group)
{
    group.MapGet("/", GetAllProducts);
    group.MapGet("/{id}", GetProductById);
    group.MapPost("/", CreateProduct);
    group.MapPut("/{id}", UpdateProduct);
    group.MapDelete("/{id}", DeleteProduct);
    return group;
}

This is the pattern that lets Minimal APIs scale to real-sized projects, one static class (or file) per resource, each contributing a route group, instead of one controller class per resource.

Validation, Now Built In

Until .NET 10, validating a Minimal API request body meant either writing manual checks or reaching for a third-party library. .NET 10 adds built-in validation driven by standard System.ComponentModel.DataAnnotations attributes. It’s opt-in at startup, then automatic on every annotated request model from there:

// Program.cs
builder.Services.AddValidation();

// Request model
public record CreateProductRequest(
    [Required] string Name,
    [Range(1, 1000)] int Quantity);

app.MapPost("/products", (CreateProductRequest request, IProductService service) =>
{
    // request has already passed validation by the time you get here
    return TypedResults.Created($"/products/{request.Name}", request);
});

A failed validation returns a 400 Bad Request with the details automatically, no manual ModelState.IsValid check required. If you need to opt a specific endpoint out, chain .DisableValidation() onto its route builder.

Filters: Minimal APIs’ Answer to Action Filters

For cross-cutting logic, logging, timing, custom auth checks, endpoint filters play the same role that action filters play in MVC:

app.MapGroup("/api/products")
   .AddEndpointFilter(async (context, next) =>
   {
       var stopwatch = Stopwatch.StartNew();
       var result = await next(context);
       app.Logger.LogInformation("Request took {Elapsed}ms", stopwatch.ElapsedMilliseconds);
       return result;
   });

Filters can be applied to a single endpoint or, as above, to an entire route group at once.

Minimal APIs vs. MVC Controllers: When to Use Which

Neither approach is a strict upgrade over the other – they’re suited to different shapes of project.

Minimal APIs in .NET - comparison-table

As a rule of thumb: reach for Minimal APIs on microservices, internal tools, and most greenfield APIs. Reach for MVC controllers on large, long-lived APIs where your team already has conventions built around model binders, filters, and a controller-per-resource structure – or where you’re maintaining an existing controller-based codebase and a rewrite isn’t justified.

Wrapping Up

Minimal APIs aren’t a toy or a stepping stone to “real” ASP.NET Core, as of .NET 10, with built-in validation, first-class OpenAPI 3.1 support, and route groups that scale to large APIs, they’re a fully production-ready option that a growing share of new .NET services are built on. If you’ve only worked with MVC controllers so far, building one small service with Minimal APIs is worth the afternoon, it changes how much ceremony you assume an API endpoint needs.

Frequently Asked Questions

Which .NET version do I need for Minimal API validation?

Built-in validation for Minimal APIs was added in .NET 10. On earlier versions, you’d need manual checks or a library such as FluentValidation.

Do I have to enable validation, or does it work automatically?

You need to call builder.Services.AddValidation() once at startup. After that, any request model decorated with DataAnnotations attributes is validated automatically.

Can Minimal APIs use dependency injection the same way controllers do?

Yes. Services registered in the DI container can be injected directly as handler parameters, without a constructor.

Are Minimal APIs only good for small projects?

No. Route groups, filters, and per-resource organization let Minimal APIs scale to large codebases. The “too simple for real projects” reputation predates MapGroup and built-in validation.

Should I rewrite my existing MVC controllers as Minimal APIs?

Not automatically. If a controller-based codebase already works and your team has conventions built around it, a rewrite usually isn’t worth the risk. Minimal APIs make more sense for new services.

Sources