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. Minimal APIs are designed to enable the creation of HTTP APIs with minimum lines of code.
Minimal APIs are covered in more detail in my companion book, Apps and Services with .NET 7, in Chapter 9, Building and Securing Web Services with 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.
It will listen on port 5003
and only GET
requests are allowed:
- Use your preferred code editor to open the
PracticalApps
solution/workspace and then add a new project, as defined in the following list:- Project template...