Join Morten Rand-Hendriksen for an in-depth discussion in this video Understanding routes and endpoints, part of WordPress: REST API.
- [Instructor] Interacting with the WordPress REST API is done through accessing routes and endpoints. These two are connected terms that are used together, so they should be explained together. An endpoint is a function available through the API, the verbs I mentioned in the REST definition. An endpoint performs a specific function by taking one or more parameters and returning the resulting data. A route is the name you use to access the available endpoints. In layman's terms, the route is the URI, the endpoint is the action performed on the URI.
To see how this works, we need an example. Let's say I want to get the contents of a specific post from WordPress with the post ID 456. I can achieve this by using the get endpoint at the wp/v2/posts/456 route. If you have the correct authentication in place, meaning a username and password that gives you the correct privileges, the same route also has two additional endpoints, put, which grabs the existing data and returns it once it's been updated and delete which deletes the data entry from the server.
The WordPress REST API provides a long list of routes and different routes have different endpoints. Later in the course we'll explore some of the more common ones and I'll explain how to discover and use all of them.
- Using a REST client to communicate with a REST API
- Reviewing available routes, endpoints, and arguments
- Adding custom post types and taxonomies
- Altering the API response
- Using PHP for resiliency
- Passing info using wp_localize_script()
- Setting up a REST API request through AJAX
- Outputting selected post data to the front end
- Formatting post data to match a theme
- Triggering AJAX for an infinite scroll effect
- Using AJAX to load subsequent responses