Websites & Apps

{"type":"PARAGRAPH"

DROPIDEA By Admin
June 1, 2025 7 views
DROPIDEA | دروب ايديا - {"type":"PARAGRAPH"

The WordPress REST API is a feature built into a custom plugin in newer versions of WordPress. This feature helps the WordPress website interact with any external application, whether it is a web application, mobile application, or something else, by facilitating the process of sharing site data with these applications easily. In today's article, we will explain to you all the details about the REST API feature, its most important terms, and how to benefit from it on your site. We will explain in a practical way how to use it to obtain site articles and modify them easily, with an explanation of how to activate and deactivate this feature on your site if you wish not to use it.

Contents of the article What is the meaning of API What is the feature of WordPress REST API The importance of WordPress REST API Using the WordPress REST API plugin Initial concepts Fetching data from the site using the API Updating site data using the API How to delete data from the site using the API Activating the WordPress REST API in old WordPress versions Deactivating the WordPress REST API Practical applications on the uses of the REST API plugin 1- The advanced Gutenberg editor 2- The UsTwo platform 3- US TODAY website What is the meaning of API API repairer is an abbreviation for the following words (A Application P rogramming Interface) i.e. an application programming interface, which generally means creating a connection point between a specific application or software system; And between you as a backend developer. Where the backend programmer can benefit from the services and results of this application or software system in the website or mobile application without having to rebuild it again. For example, if you add Google Maps to your WordPress site, in this case you are using the Google Maps API to connect your WordPress site to Google Maps.

Likewise, when the Facebook Like button is added to a page on your WordPress site, this is done by linking the Facebook API to your site. You enable that web page to use the API to receive data (like button) and send data (like request).

What is the feature of WordPress REST API interface

REST APIs, short for Representational State Transfer, are a type or standard of application programming interface that follows a programming approach that defines how web services communicate with each other over the Hypertext Transfer Protocol (HTTP). There are many types of application programming interfaces (API), but REST is considered the most popular and newest. It works by processing text data for external applications without the need for direct access to the database of these applications. The WordPress REST API is used in WordPress to help WordPress developers connect their WordPress site with other external websites, web applications, or mobile applications. It also helps developers access the site's database, retrieve data from it, and add data to it.

Through this feature, you will be able to obtain the information you want from the WordPress website database in JavaScript Object Notation (JSON) format. It is a language specifically designed to send, receive and store data. As it stores data in pairs (key and value), then you can display this data in any other programming environment, even if this environment does not use the PHP language on which WordPress depends.

For example, if you want to create a mobile application for your phone that does not depend on WebView, which usually displays an identical copy of all your website data within an iframe, and you want to pull some site-specific data only such as (articles, media, pages, classifications, or other specific data), in this case you need to use a REST API that organizes this data and makes it available to the mobile application developer so that he can automatically reuse it in the application. The importance of the WordPress REST API The REST API is included in modern versions of WordPress (4.7 and later) implicitly in the form of an automatically activated REST API add-on to enable developers to share all WordPress site data with all external web or mobile applications, and facilitates the process of programming any application that relies primarily on its data from the WordPress site. Without it, you will need to program the API for your site from scratch, which is very expensive. In addition, the add-on helps you receive data from external parties also within your site and not just send it. On WooCommerce sites, for example, the add-on receives requests from any external application, saves them on your site in a simplified manner, and also re-sends the request data to the application so that it appears to the customer.

This feature is also considered very important in all WordPress sites and is indispensable in any site, even if you do not need to create any external applications, as the REST API addition works in modern versions of WordPress in a built-in manner and is necessary for the functioning of some features such as the Gutenberg component editor. This feature has enabled WordPress to evolve from just a website creation platform to become a full-fledged application framework. It enables developers to use it to create mobile and web applications with great ease.

Read also: Explaining Progressive Web Applications (PWAs), their features, and how to create them. In the following paragraphs, we will explain to you how to benefit from the WordPress REST API to fetch specific data from any WordPress site with practical examples. Using the WordPress REST API plugin in the beginning, before explaining the plugin, you must know some basic concepts that any developer who will use this technology needs to understand its meaning: Initial concepts Route (router): It is the link that enables you to access the site with the different certificates used, such as HTTP or Https. EndPoint: It is the connection created between http and the Route. To reach an endpoint, you must use a path that takes the form of a regular URL. An example of this is the following path http://yourdomain.com/wp-json/, which returns all the content and metadata of your site in JSON format.

Request: It is a command issued by WP-Rest_Request, and it is used to fetch and store information for the current request. Response provides the data for which the Request was made, and if it is not available, an error message is forwarded with an explanation of the reason, so that you can fix it. Schema: You can convert all inputs and properties into lists, which the Rest API can accept and redirect to use.

Controller Classes This is where you can manage all parts of the Rest API plugin. Fetching data from the site using the API. In this part, we will explain how to fetch data from the site using the Rest API. First, you need to know that your entire interaction will be with your site’s domain via the wp json file path to the next page http://yourdomain.com/wp-json/. You should also know that there are three basic JSON requests that you will use with the REST API, which are (a GET request to retrieve data from the API, a POST request that enables you to send new information to WordPress, and a DELETE request to delete Data) In order to be able to implement these requests, follow the following steps: 1- In order to be able to access the WP-REST API, you will first need to access your site via the command line. This can be achieved on WordPress sites by installing the W P -CLI tool, which is a command line tool intended for developers to enable them to manage tasks in WordPress. To install WP-CLI make sure that your hosting account supports SSH access as most shared hosting providers do not give you SSH access.

2- After installing the command line interface and connecting to your site through it, you must first test the connection and ensure that the data can be retrieved from the required page, by typing the following command: curl -X OPTIONS -i http://yourdomain.com/wp-json/ 4. The following message will appear, which means the connection was successful: HTTP/1.1 200 OK Date: Wed, 23 Oct 2021 19:51:41 GMT Server: Apache/2.4.29 X-Robots-Tag: noindex Link: ; rel=”https://api.w.org/” charset=UTF-8 After a successful connection, you can retrieve any content from the site. Write the following GET request first to get a JSON response that shows you the available paths you can fetch data from and the available endpoints within each path.

Curl - https://wpar.net//wp-json/wp/v2/posts where you will get a lot of information about all the site’s articles. The information may not seem understandable to you at first, but it contains a lot of important information in JSON format such as ID, name, date, and texts of articles published on our site. You can then use this information in an application for example and display it in an understandable way using your own custom design.

If you want to retrieve content from website pages only, use the following line: curl -X GET -i http://yourdomain.com/wp-json/wp/v2/pages. You can also change the data that will be obtained by changing the parameters passed to the link in the previous code. For example, if you add per_page = 5 as follows https://yourdomain.com/wp-json/wp/v2/posts?per_page=5 you can get data for only 5 posts. Thus, all you have to do is simply change the hover link and get the information you want from the site. The next stage is to use this information by other platforms to display it appropriately (this information is usually analyzed using the JavaScript programming language and the data is output in an easy-to-read format using HTML) Updating the site data using the application programming interface. The REST API is characterized by being very easy to use to modify the content of a specific article that you must specify at the beginning. To specify specific content to modify or update, first write the following line: curl -X GET -i http://yourdomain.com/wp-json/wp/v2/posts After that, find the ID of that article that you want to update, and add it in place of the ID in the next line: curl -X GET -i http://yourdomain.com/wp-json/wp/v2/posts/ Now you can, for example, change the title of the article, by using the following POST request while changing the value of the title with the new title by passing it as an argument as follows: curl -X POST --user username:password http://yourdomain.com/wp-json/wp/v2/posts/PostID -d '{"title":"My New Title"}' There are plenty of other arguments you can use to make changes to an article.

For example, you can change the category or rating of an article, change its publication status, or change its entire contents. How to delete data from the site using the API Now we will show examples of how to remove data from the site using the REST API. For example, to delete a user from the site.

You can use the following DELETE request to delete a user with ID =10: curl -X DELETE http://example.com/wp-json/wp/v2/users/10 This will remove the specified user from the site. You can also later use additional parameters to reassign this user's articles to another user based on the user ID or permanently delete his articles from the site.

Note: Sometimes when executing some commands

(such as commands to update or delete content) You may be asked to be able to register as an administrator. In order to be able to do this, you must install and activate the REST API Basic Auth plugin on your site. After activating the add-on, open the CLI command line interface, then type the following command so that you can make a request on the REST API with administrator privileges, replacing the user name and password with the words for the admin account on the site.

curl -X GET --user username:password -i http://yourdomain.com/wp-json/wp/v2/posts?status=draft Then fetch any data you want from within the wp-json path as we explained. If you would like to view all the links and data that you can access on your site, we advise you to go to the following link: Reference handbook. Thus, we have shown you some practical examples of how to obtain data through the REST API. All you have to do is learn the RESET API technology and learn the basics of JSON to acquire the basic skills for dealing with the data provided by your site.

If you are using an old version of WordPress and want to take advantage of this technology, you can simply activate the REST API add-on on your site as follows: Activating the WordPress REST API in old versions of WordPress As we mentioned at the beginning of the article, if you are using old versions of WordPress (version 4.7 or earlier), then the REST API add-on will not be activated with the WordPress system by default, and in this case you will have to install the REST API add-on manually in order to be able to use it and benefit from its features. Note: You can find out the version of WordPress for your site by going to the bottom of the main admin page, where you will see the phrase “Thank you for using WordPress,” and next to it is the phrase “version xxx,” where xxx represents the version number of WordPress used on your site. To install this plugin on an old version of WordPress.

Download the add-on from the following link: REST API Add-on. Upload the add-on to your site through: Add-ons>Add New>Upload Add-on. Click on the Activate Add-on button. Thus, the add-on will be activated successfully. After that, you will not need to set anything, as the add-on works on its own. Thus, you have ensured that the add-on is activated on your site. Please note that if you install security plugins on your site, these plugins may disable the WP REST API feature activated on your site, so make sure to allow their use on your site. Deactivating WordPress REST API Sometimes the REST API plugin is misused by unknown developers to create an application or website that relies primarily on data taken from your site, or in any other way.

So if you are not using the REST API features on your site directly and do not need them later, you may need to turn them off, especially if you are working with recent versions of WordPress that have the feature built-in. To do this, you must install and activate the Disable WP REST API plugin on your site. You can also disable this feature manually through the file Function.php by adding code inside it.

By entering the template editor, then choosing the template used, after that you will find the functions.php file at the beginning of the template files, then edit it and add the following code to it. add_filter( 'json_enabled', '__return_false' ); add_filter( 'json_jsonp_enabled', '__return_false' ); Practical applications on the uses of the REST API plugin. Below we mention to you some examples of practical applications created using the REST API plugin integrated into WordPress. 1- The advanced Gutenberg editor. This application is one of the most famous applications based on the RESET API feature, but how is it already present on your site?

The answer to this question is that the advanced Gutenberg editor implicitly uses the RESET API to access the database and create blocks. 2- UsTwo platform UsTwo is a digital company whose website was created based on adding the RESET API as a single page application. The basic interface was programmed in the React language, while the backend is built on WordPress with some modifications to suit the site’s uses, and the idea of ​​​​the site’s operation depends entirely on the RESET API mechanism.

3- The US TODAY website. Part of the famous news website USA Today relied on the RESET API mechanism to share the site’s content on other platforms such as Facebook Instant Articles, Apple News, and other news services that help spread news on the Internet. Conclusion: In this article, we learned about the concept of the API, which is a function that connects different systems to each other. We explained how the RESET API works in WordPress and its most important features. We have provided some examples of the process through which you can manage the content of your site.

We advise you, as a WordPress developer, to delve deeper into the RESET API technology and learn the JSON format so that you can share WordPress website data with any party you want, and master the task of building external applications based on the content of WordPress websites easily.

DROPIDEA

We hope this article has added real value to you. At DROPIDEA, we always strive to deliver high-quality content that helps you grow and evolve in the digital space. Follow us for more useful articles and guides.

Share Article