Implementing REST in ASP.NET Core
An API created in ASP.NET Core will typically have three major components:
- Controllers
- Services
- Repositories
Note
There is an alternative to controller-based APIs known as Minimal APIs. We discuss this in brief towards the end of this chapter (refer to the Minimal APIs box). We do not cover Minimal APIs for the rest of the book as they have too many limitations.
When you invoke an API with a URL, that address is resolved to a controller. For example, using the URL we saw earlier, if you call https://localhost:7025/Car, you will invoke the CarController
at that address. Note that ASP.NET uses “convention over configuration,” by which we mean that by convention, the part of the word Controller is left off the address but is implied. So in this case, CarController
, the address just uses Car
(leaving off Controller).
The job of the controller is to ensure that the user has been authenticated (it’s really...