From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Route to controllers with templates

Route to controllers with templates - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Route to controllers with templates

- [Narrator] Let's add another controller to the project to handle the slash rooms route. This route will let the client search for a room in the hotel. In the controllers folder I'll add a new class called rooms controller (typing). Then we'll inherit from controller base. Import the name space. Add the API controller attribute. We'll use the same pattern here of creating a named get method, and annotating it with an http get attribute and a route name. So I'll do public I action result, get rooms. For now I'll just throw a not implemented exception. On the action method I'll say http get. And the name will be just the name of the method, get rooms. We also need the route attribute on the controller. On the route controller, this was hard-coded to slash, but in this case, we want the controller to handle requests to slash rooms. Instead of hard-coding slash rooms, we can use a template stream, like slash bracket controller. The bracket controller template will automatically match the…

Contents