- Overview
- Transcript
4.2 OPTIONS Requests
If we need to learn about a certain route, then sending an OPTIONS request is the easiest way. In this lesson, I'll show you how to explore individual routes, their endpoints, and their supported arguments.
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
4.2 OPTIONS Requests
Hey folks and welcome back to the course Introducing the WP REST API. I'm your instructor Bilal Shahid. In the previous lesson we took a look at retrieving fundamental information about the API by sending a get request to the index route. This information contains things such as the site name, its description, supported authentication methods and all the supported routes. But this information can be a bit confusing if you just want to exclude a particular route. For excluding a particular route, its methods and its supported arguments, it's more feasible to send an options request to get particular route. Let's begin by sending an options request to the posts route. This returns an object that contains various properties like the namespace this route belongs to, its support methods and its supported endpoints. It's clear from the response that this route belongs to the default wp/v2 namespace and its supported methods are GET and POST. That is, we can use this route to retrieve and create posts. For retrieving posts, the get method is used and its supported arguments are context, page per page, search, etc. The format of this data is exactly the same as we saw in the previous lesson when sending a GET request to the index route. And for creating posts, the POST method is used, and for creating a post you can use all of these arguments that include date, date_gmt, password, slug and status. This is very much similar to what you saw in the previous lesson when sending a GET request to the index route. In addition to these properties, the response also contains the schema property that defines the schema of the current resource. This schema is basically a documentation for all the properties supported by the resource like its description, its data type, its format and context. The schema used in the WP REST API is based on the draft four of the JSON schema specifications. So, that's all about navigating the API by sending an options request. In these two lessons, we looked at ways for exploring the API by sending either GET request to the index route or by sending an options request to a particular route. It's up to you what method you use. If you need to list all the supported routes for the API, you can send a GET request to the index route, but if you need to look at a particular route more closely, you can send an options request for that particular route. In the next lesson, we will use their techniques learned so far to retrieve data with the help of WP REST API. See you in the next video.