Attribute Routing

noun

say it: “AT-rih-byoot ROW-ting” /ˈætrɪbjuːt ˈraʊtɪŋ/

Setting a controller action's address with an attribute on it, such as [HttpGet("products/{id}")].

What is Attribute Routing?

Attribute routing puts the URL pattern right on the controller or method with [Route], [HttpGet("...")] and friends.

[Route("api/orders")]
public class OrdersController : ControllerBase
{
    [HttpGet("{orderId:int}/items")]
    public IActionResult Items(int orderId) => Ok();
}

In a sentence

  • “With attribute routing, the address sits right above the action it calls.”

Level: Apprentice · More ASP.NET Core terms at this level

Updated