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.

Create a root controller

Create a root controller - ASP.NET Core Tutorial

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

Start my 1-month free trial

Create a root controller

- [Instructor] Let's build a simple route controller that will serve as the starting point for the API. First, I'll delete this default values controller that was created by the template. And then, in the Controllers folder, I'll add a new class called Root Controller. Controllers in ASP.Net Core inherit from the Controller class. Lemme import the name space here, aspnetcore.nbc. For API controllers, you can use the controller base class, which is a stripped-down version without the view and razor features you only need in a web app. API controllers use route attributes to tell the routing system which routes they should handle. In this case, this controller should handle the slash, or root route. So we'll say slash. I'll also add the API controller attribute. This lets ASP.Net Core know that I'm building a controller meant for an API. This opts us in to some nice extra features like automatic model validation. If we create a method called Get, ASP.Net Core MVC will automatically…

Contents