We will now move on with some practical work, which will consist of us setting up our endpoints. As we have previously stated, routes would only be useful if they have endpoints, which is why the rest of this chapter will only cover the process of adding endpoints to the route using our third argument of register_rest_route()
.
The transport method involves endpoints that need to define one or more HTTP transport methods, such as DELETE, POST, PUT, and GET. With an endpoint that is defined as working via a GET request, the REST API will receive the correct data and the way to create errors for invalid requests.
The array that defines your endpoint will further define the transport methods in a key named method. The following code example will provide you with the method of defining an endpoint that is going to allow only for GET requests and will underline the process on how the WP_REST_Server
class provides constants for defining transport methods...