Proof of Concept of Minimal APIs with .NET 7.0
Minimal APIs are a new feature in .NET 7.0 that allows developers to build HTTP APIs with minimal coding, setup, and configuration. It simplifies the process of setting up a web API project and allows for a more concise programming model.
This is a proof of concept for using minimal APIs to create a simple API that allows to:
- Get a list of pets
- Get a single pet.
- Create a new pet.
It's a full fledged API with a Sql Server database, unit testing and everything. It's just a proof of concept, so it's not perfect, but it works and demonstrates the concept offered by Minimal APIs.
Prerrequisites
- .Net 7.0
- Microsoft SQL Server
Steps Outlined
- Clone the repository.
- Either open the solution file with Visual Studio or use the dotnet CLI. If you opt to use the dotnet CLI follow steps 3 through 8, if you don't want to use the dotnet CLI then just do the following after opening the solution file in Visual Studio:
- Restore NuGet packages for the whole solution.
- Run the database migrations located in MyMinimalApi.Data.Migrations directory, and insert some seed data into the PetDb database.
- Build the solution
- Run it
- Play with the API either directly in the browser or using the Postman tool.
- Go to the root folder of your local repository.
- Restore the NuGet packages used. Basically they are:
- Microsoft EntityFrameworkCore
- Microsoft EntityFrameworkCore for Sql Server
- Microsoft EntityFramework InMemory
- Microsoft AspNetCore TestHost
- Microsoft Extensions
- Microsoft.Net Test SDK
- xunit
- Moq
- Coverlet Collector
- Build the solution using the following command:
dotnet build
. - Run the database migrations located in MyMinimalApi.Data.Migrations directory, and insert some seed data into the PetDb database.
- Go to the MyMinimalApi project directory.
- Run the MyMinimalApi project using the following command:
dotnet run
. - Play with the API either directly in the browser or using the Postman tool.
- Go to the MyMinimalApi project directory.
- Run the MyMinimalApi project using the following command:
dotnet run
. - Play with the API either directly in the browser or using the Postman tool.
Et voilĂ !