Actions
The web API has many actions, some of which were covered in Chapter 2, Understanding HTTP and REST, with examples. As a refresher, we will go over them again as we will want to use these actions when we create our controller. The Action
attributes will be used to decorate a method.
Every action should be thought about from a consumer's point of view; for example, for Post
, the client is posting something.
If we had created ShoesController
, the route for this would be as follows:
[Route("api/[controller]")]
Post
This action is used when we want to create something. The body of the message will contain the data that needs to be saved to a data store:
[Route("")] [HttpPost] public IActionResult CreateShoes([FromBody] ShoeModel model)
The first line is the route, routes should always be declared. They give someone who is reading the code or debugging the code a better understanding of what is happening and how the flow is.
In the second line, we state the Action
attribute...