Rest APIs are becoming more and more popular among developers for a reason. Provide a simple, unified and easy to understand interface for third-party services such as twitter, MailChimp and GitHub. The WordPress API is in progress (already available through plug-ins), which is the best time to learn about the HTTP API that already exists in WordPress. In this article, I will show you what it is, how it works, and what it can be used for. What is the HTTP API? Of course, the HTTP API is a way to send and receive messages using the web language http. Browsers always send and receive HTTP messages as web pages. Through the rest API, HTTP messages can perform more elaborate tasks, such as updating posts, deleting users, or publishing new recipes on the website. The
That’s why the new WordPress API is important, allowing you to separate the user – oriented aspects of your application from the core WordPress code. To use it, you must be familiar with sending HTTP requests and receiving responses. This is all about the HTTP API. There are many ways to send HTTP requests. The HTTP API provides an integrated interface using the following helper functions: HTTP methods and resources HTTP is centered on methods (also known as verbs) and resources. Resources define the items that need to perform specific actions when defining the behavior types you want. The
A resource is a URL that points to an object on the web, such as a post. There are many methods, the most important of which are get, post, put and delete. Get is used to search resources, so it has a lot of experience. When reading this article, the browser https:\/\/wpmudev.com\/blog\/using-the-wordpress-http-api\/ Get request. Put requests are used to modify resources, post requests are used to generate resources, and delete requests are used to delete resources. If wpmu dev has a rest API, the administrator will request delete https:\/\/wpmudev.com\/blog\/wordpress-http-api\/ You can delete a post by sending. This can be useful for large web sites with self managing mobile applications. The
Send a simple get request to test the simple request. This can be achieved by using the wp\u remote\u get() function, which takes two parameters. The first parameter is the full URL of the resource, and the second parameter is an array of options that can be used to specify details. Loading points c7e98b9596bfb6d085b0 will search the Google home page. If you dump the value of the response $test returned by Google, all relevant elements must be displayed. The header contains additional information for each message. Some rest APIs require that specific information be sent to the notifier on request. The
The response includes 404 errors, 500 server errors, or possibly familiar status codes and statements in 301 and 302 redirects. W3.org defines and describes all HTTP error codes. It is a good resource to understand what errors mean. This article includes responses, usually where you need to find something good. In this case, you will receive the full HTML of the Google home page. When using the rest API, the standard convention is to receive JSON encoded data strings. Sometimes the API requires that a specific string be added to the body of the request. The
The cookies section contains all cookies received with the message. As you can see, use the HTTP API.
Programme. The HTTP API helper function now has a good understanding of what this is for, so let’s take a look at all the functions that the WordPress HTTP API can help. You can use the following 4 functions to request: Wp\u remote\u get() wp\u remote\u post() wp\u remote\u head() wp\u remote\u request(), which is quite self-evident. The last wp_remote_request() is a generic function that can be used with all HTTP verbs. Five additional features allow you to easily search for responses using the standardization function instead of using the tile key. Wp\u remote_retrieve_body() wp\u remote_retrieve_headers() wp\u remote_retrieve_response_code() wp\u remote_retrieve_response_message() is again very easy to understand. If possible, use these functions instead of manually moving to the response array. This helps other developers follow and use the hook when they can use it later. As the API operation shows, it is very easy to interact with the rest API because it uses other word press functions, such as the word press HTTP API and temporary functions. WordPress development is confidently moving towards an API centric world, so I strongly recommend that you try all this. Before it’s too late, start now! Generally, if you need more information about HTTP, we strongly recommend James marshall’s guide, which details HTTP verbs, resources, errors and other matters. If you have any questions about using the HTTP API or have any ideas about how to use it, please tell us the following comments: Label: API http