Building web services using minimal APIs
For .NET 6, Microsoft put a lot of effort into adding new features to the C# 10 language and simplifying the ASP.NET Core libraries to enable the creation of web services using minimal APIs.
You might remember the weather forecast service that is provided in the Web API project template. It shows the use of a controller class to return a five-day weather forecast using faked data. We will now recreate that weather service using minimal APIs.
First, the weather service has a class to represent a single weather forecast. We will need to use this class in multiple projects, so let's create a class library for that:
- Use your preferred code editor to add a new project, as defined in the following list:
- Project template: Class Library /
classlib
- Workspace/solution file and folder:
PracticalApps
- Project file and folder:
Northwind.Common
- Project template: Class Library /
- Rename
Class1.cs
toWeatherForecast...