.NET is a great technology to create robust APIs. Until .NET Core 3, the main approach based on Microsoft documentations was to create a web API with Controllers. In .NET 6 Microsoft adopted an innovative approach like Express.js approach. The name of this, Minimal Web API. But first things first…
What is Minimal API
Minimal API is a new architecture that .NET adopted, to create HTTP APIs with less code than in the past. You can have a deploy-ready API with two files:
- Program.cs : You can write your code here
- NameOfTheProject.csproj : Tha name of the project
What is Minimal API with more words
The .NET Minimal API is a stripped-down version of the .NET that is designed specifically for building microservices. It is a lightweight, modular, and portable runtime that allows developers to build highly scalable and resilient microservices that can run on any platform.
One of the benefits of using the .NET Minimal API for microservices is its small size. The runtime is designed to be as lightweight as possible, which makes it easier to deploy and manage microservices in a cloud environment. It also reduces the attack surface of the microservices, making them more secure.
Another benefit of the .NET Minimal API is its modular design. It consists of a set of NuGet packages that can be added to a project as needed. This allows developers to only include the features that they need, reducing the size of the microservice and improving performance.
When Minimal API is better than Controller’s API
Creating a web API with Controllers is a common way to create APIs in the .NET environment. MVC pattern is the common pattern to create .NET APIs with Controllers and it is a popular, well-tested approach running in the most .NET applications worldwide. Minimal API is designed specifically for building microservices, and you want to implement small applications that handle specific operations.
Create Minimal API from the Commander
You need .NET CLI to run these commands
dotnet new webapi -minimal -o NameOfTheApiProject
Run Minimal API from the Commander
dotnet run
More