Search⌘ K
AI Features

Building Web Services Using Minimal APIs

Explore how to build efficient web services using Minimal APIs in ASP.NET Core and C# 10. Learn to configure projects, implement a weather forecast API without controllers, and integrate it into an MVC website. Understand testing techniques and how Minimal APIs simplify web service development.

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 ...