Building Web Services Using Minimal APIs
Learn about creating web services with Minimal APIs, configuring HTTP clients to call the service, and integrating the weather forecast into an MVC client website.
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. We 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.
Recreate weather service
We will now recreate that weather service using Minimal APIs. It will listen on the port GET requests are allowed:
Step 1: Use the preferred code editor to open the PracticalApps solution or workspace and then add a new project, as defined in the following list:
Project template:
ASP.NETCore Web APIorwebapiProject file and folder:
Minimal.WebApiWorkspace or solution file and folder:
PracticalAppsAuthentication type:
NoneConfigure for HTTPS:
SelectedEnable Docker:
ClearedUse controllers (uncheck to use Minimal APIs):
Cleared / -minimalEnable OpenAPI support: ...