In the second version of REST API, there is a new function called register_rest_route()
that deserves our attention. It lets you add a route to REST API and then further pass it to an array of endpoints. For each endpoint provided, a defined value for each field will be given in our query, including defaults, validation and callbacks, sanitation, and separate permissions callback.
The focus will be put on the following three main key points:
Callback
Field arguments
Permissions check
They will provide us with an idea on how the architectural side of the API functions. It is important to note that you will know that your requests are authorized, and your fields sanitized, and everything is in place once we get to our callback. This very same architectural structure is what will enforce separation of concerns and help maintain your code modular.