...

/

Building Web Services Using Minimal APIs

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 50035003 and only 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.NET Core Web API or webapi

  • Project file and folder: Minimal.WebApi

  • Workspace or solution file and folder: PracticalApps

  • Authentication type: None

  • Configure for HTTPS: Selected

  • Enable Docker: Cleared

  • Use controllers (uncheck to use Minimal APIs): Cleared / -minimal

  • Enable OpenAPI support: ...