Do you use Minimal APIs over Controllers?

Last updated by Brady Stroud [SSW] 5 months ago.See history

Traditional controllers require a lot of boilerplate code to set up and configure. Most of the time your endpoints will be simple and just point to a mediator handler.

Minimal APIs are a simplified approach for building fast HTTP APIs with ASP.NET Core. You can build fully functioning REST endpoints with minimal code and configuration. Skip traditional scaffolding and avoid unnecessary controllers by fluently declaring API routes and actions.

Check out the Microsoft Docs for more information on Minimal APIs.

public class HelloWorldController : ControllerBase
    public IActionResult Get()
        return Ok("Hello World!");

Figure: Bad Example - 9 lines of code for a simple endpoint

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

Figure: Good Example - 1 line of code for a simple endpoint

Minimal APIs are great for

  • Learning
  • Quick prototypes
  • Vertical Slice Architecture
  • A similar developer experience to NodeJS
  • Performance
We open source. Powered by GitHub