From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Creating controller-based Web APIs
From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Creating controller-based Web APIs
- [Instructor] Let's now focus our attention on controller-based web APIs. Before I create a new project, let's use the .NET CLI to review some of the options for creating new web APIs. I'll bring up a list of the available asp.net core project templates with the dotnet new list asp.net. The third template in the list is the one we're interested in. The short name for it is just webapi. However, that doesn't distinguish controller-based APIs from minimal APIs, so let's look at the options we can include when creating a new project. I'll do that with the command dotnet new webapi --help. There are lots of options available in this list, but the one I want to focus on now is the last one at the end. The controllers or use controllers option is a Boolean. If it's true, then a controller based API will be created. The default value for this option is false, so to make sure I now create a new controller-based API, I'll use the command dotnet new webapi --use-controllers. I'll add the -o…