Endpoints are functions available through the API. This can be things like retrieving the API index, updating a post, or deleting a comment. Endpoints perform a specific function, taking some number of parameters and return data to the client.
A route is the “name” you use to access endpoints, used in the URL. A route can have multiple endpoints associated with it, and which is used depends on the HTTP verb.
For example, with the URL http://example.com/wp-json/wp/v2/posts/123
:
- The “route” is
wp/v2/posts/123
– The route doesn’t includewp-json
becausewp-json
is the base path for the API itself. - This route has 3 endpoints:
GET
triggers aget_item
method, returning the post data to the client.PUT
triggers anupdate_item
method, taking the data to update, and returning the updated post data.DELETE
triggers adelete_item
method, returning the now-deleted post data to the client.