- Overview
- Transcript
2.2 Routes and Endpoints
In this lesson, I'll explain the difference between routes and endpoints and how they work to power the REST API.
1.Introduction1 lesson, 01:17
1.1Introduction01:17
2.How REST APIs Work3 lessons, 15:33
2.1HTTP Methods and Response Codes04:34
2.2Routes and Endpoints03:43
2.3JSON07:16
3.Set Up the Environment2 lessons, 08:22
3.1Set Up a Local WordPress Install04:16
3.2Installing the HTTP Client Postman04:06
4.Exploring the WordPress REST API4 lessons, 21:43
4.1The Index Route05:59
4.2OPTIONS Requests03:26
4.3Retrieve Data With GET Requests05:28
4.4Create, Update, and Delete Data06:50
5.The WordPress REST API in Action2 lessons, 16:47
5.1Retrieve Data With jQuery08:02
5.2Create Data With the WP REST API and jQuery08:45
6.Conclusion1 lesson, 00:59
6.1Conclusion00:59
2.2 Routes and Endpoints
Hey, folks, and welcome back to the course introducing the WPS API. I'm your instructor Bilal Shaheed. Another important concept when working with JS API is routes and endpoints. They are often confused for each other, but in reality they are quite different. In this lesson, we will take a look at what they actually are and how they differ from each other. While routes are a way to point to a particular resource, endpoints are functions that perform several actions on these resources. These actions can be retrieving, creating, updating or deleting a particular resource. Alternatively, we can say that and endpoint CRUD mattered that performs a specific task. And since we are talking about performing CRUD operations, these endpoints are closely associated with HTTP verbs. Let me demonstrate by an example. Here, we have our get points to the post resource in the WordPress for JPI. This route has two endpoints for retrieving and creating posts. So the first endpoint triggers the get method that is responsible for retrieving a collection of posts. And the second endpoint triggers the post method that is responsible for creating a new post. And this endpoint also contains the functionality for checking for authentication and validating the provided data before it actually creates a post. Similarly, this is the route that points to a particular post having an ID of 10. This route has three endpoints responsible for creating, updating and deleting and that particular post. The first endpoint uses the GET method, and it retrieves a post having an ID of 10. The second endpoint uses the PUT method and is responsible for updating this post with new data. And since a updating a post requires authentication, the functionality to authenticate a user would be implemented here in this endpoint. It's worth noting that some APIs use both put and post methods for updating a resource, and this is also the case with JSWPSAPI.. So we can send a put or a POST request to a particular source, and both request will have the same effect and they will update the resource with new data. The third, and the last endpoint is used for deleting the posts having an ID of 10, and it uses the delete method. Deleting a post also requires authentication, so the user would need to post proper credentials for performing this operation. In these examples, we use the post resource, but these concepts will remain the same whether we are working with posts, pages, users or any other resource supported by the WPS API. So that was a pretty basic overview of what routes and endpoints are and how they work. In the next lesson, we will take a look at JSON that is presenting data and is used quite heavily in the WPS API. See you in the next video.