Search⌘ K

Understanding Controllers

Explore the role of controllers in ASP.NET Core Web API development. Understand how action methods process HTTP requests, handle routing with annotations, and return JSON-formatted responses. This lesson helps you grasp the backend request/response pipeline and how controllers work within the framework.

Implementation of web API resources using controllers

Web API resources are implemented using controllers. Let’s have a look at the controller that the template project created by opening WeatherForecastController.cs in the Controllers folder. This contains a class called WeatherForecastController that inherits from ControllerBase with a Route annotation:

Node.js
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase {
...
}

The annotation specifies the web API resource URL that the controller handles. The [controller] ...