ASP.NET - What Minimal APIs Are

Minimal APIs are a feature in ASP.NET Core that let you build web endpoints with very little setup. Instead of creating controllers and separate classes, the entire API can be written directly in the Program file. This reduces complexity and makes the application start small and simple.


Why They Were Introduced

Microsoft created Minimal APIs to support fast development, especially for microservices, small applications and demo projects. Many modern apps don’t need full MVC structures, so Minimal APIs remove extra steps and let developers focus only on the routes they need to expose.


How Routing Works

Each route is mapped directly using methods such as MapGet, MapPost, MapPut or MapDelete. These routes behave like controller actions but require only a small function. Requests come in, run the code written for that route and send back a response, all in one place.


Dependency Injection Support

Even though the structure is smaller, Minimal APIs still allow services to be registered and injected. This means databases, logging and business logic modules can be used the same way they are in larger ASP.NET Core projects. The only difference is how simple the entry point code looks.


This sample app exposes two endpoints: one returns todos, and the other adds new ones.

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

var todos = new List();

app.MapGet("/todos", () => todos);
app.MapPost("/todos", (string item) => { todos.Add(item); return Results.Created(); });

app.Run();

When To Use Minimal APIs

They are best for lightweight services such as backend endpoints for mobile apps, quick prototypes or functions deployed to the cloud. For larger systems that rely on layered architecture, controllers still offer cleaner separation.