Minimal APIs are architected to create HTTP APIs with minimal code footprint. They include only the minimum files, features, and dependencies. In .Net world it usually means Web APIs without use of MVC Controller subclass.
- Minimal APIs Overview
- Minimal APIs Fundamentals in .Net
- Tutorials Minimal APIs for ASPCore.Net
- Real World Minimal Apis: Video
Following commands will get you started from scratch
dotnet new sln
dotnet new webapi --use-minimal-apis -o Weatherforecast.Api
dotnet new xunit -o Weatherforecast.Tests
dotnet sln add .\Weatherforecast.Api\ .\Weatherforecast.Tests\
In case you get certificate warning execute:
dotnet dev-certs https --trust
Add dependencies if you want persistance layer
dotnet add package Microsoft.EntityFrameworkCore.InMemory
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
Templates which scaffold projects with Minimal API and Unit tests in .Net
dotnet new --install .\templates\
Then you can create new projects with:
dotnet new miniapihello -o HelloFeature
dotnet new miniapitodo -o TodoFeature
dotnet new miniapiauth -o EmployeeFeature
If you want to remove these project examples do:
dotnet new --uninstall .\templates\
- No support for filters: For example, no support for IAsyncAuthorizationFilter, IAsyncActionFilter, IAsyncExceptionFilter, IAsyncResultFilter, and IAsyncResourceFilter.
- No support for model binding, i.e. IModelBinderProvider, IModelBinder. Support can be added with a custom binding shim.
- No support for binding from forms. This includes binding IFormFile. We plan to add support for IFormFile in the future.
- No built-in support for validation, i.e. IModelValidator
- No support for application parts or the application model. There's no way to apply or build your own conventions.
- No built-in view rendering support. We recommend using Razor Pages for rendering views.
- No support for JsonPatch
- No support for OData
- No support for ApiVersioning. See this issue for more details.
Minimal Web API are commonly used on
- Vertical Slice Architecture,
- Microservice Architecture,
- Clean Architecture,
- IoT Edge devices
- or any infrastructure components with small APIs.
Here is an example of more complex solution in .Net for Minimal API
Usage of minimal apis by packt publishing