A place I'm trying out the new ASP.NET Core minimal APIs for hosting and HTTP APIs.
Code in this repo depends on the very latest bits. If you want to try it out, grab the latest .NET 7 SDK installer.
First-class support for validation as part of the new minimal APIs is not currently planned to be implemented. However it's fairly straightforward to wire up the validation features found in System.ComponentModel.Validation
through the use of a helper library (like the example this repo uses), or by using an existing validation library like FluentValidation.
This project implements a simple Todos API including OpenAPI (Swagger) documentation and UI, and uses the Dapper library to persist data to a SQLite database.
There are some simple tests for this project in the tests/Todo.Dapper.Tests project.
This project implements a simple Todos API including OpenAPI (Swagger) documentation and UI, and uses using Entity Framework Core to perist data to a SQLite database.
This project contains numerous examples of ways to use and extend the new minimal APIs in ASP.NET Core 6/7 to build HTTP APIs.
While the Program.cs
file in the project root is where the APIs are registered and implemented, much of the custom code is in the Properties
directory. I keep it there as almost all .NET projects have a Properties
directory and I wanted to avoid additional directories in the project to avoid any implication that additional special directories are required. Ultimately it's just code and be placed anywhere in the project.
The project includes examples of the following and more:
Results
and TypedResults
helper classes to return common resultsIResult
objectsTryParse
BindAsync
IParameterBinder
that enables creating binders for types you don't ownModelBinder
implementations via a custom binding shimBindAsync
implementationHttpRequest
and returning a custom IResult
implementationMiniValidation
library
UseExceptionHandler
IAntiforgery
functionalityApiExplorer
without the need to manually annotate the route handlers with attributes or chained metadata method calls