Controller
noun
say it: “kun-TROH-ler” /kənˈtroʊlər/
A class in ASP.NET Core that handles requests for one area of the app, with a method for each action.
What is Controller?
A controller is a class that groups related endpoints as methods, such as a RecipesController. It is the classic style, still common in larger apps.
[ApiController]
[Route("recipes")]
public class RecipesController(IRecipeRepository recipes) : ControllerBase
{
[HttpGet("{id:int}")]
public async Task<ActionResult<Recipe>> Get(int id) =>
await recipes.FindAsync(id) is { } r ? r : NotFound();
}
In a sentence
- “Our products controller handles every request that starts with /products.”
Level: Apprentice · More ASP.NET Core terms at this level
Updated