WP-JSON in WordPress
Definition of WP and JSON: WP stands for WordPress and JSON is for JavaScript Object Notation. JSON is highly used in the REST API. All data will be formatted in JSON format so that the developer can easily fetch the data from the API.
What is WP-JSON:
WordPress already provides many tools and interfaces for building sites. You should not feel any pressure to use the REST API. Rest API is not for building themes or plugins of WordPress.
If you are creating your own client-side application then you need to fetch the data from your WordPress database. It’s not compulsory to create your app in only PHP language. You can choose any language to create your application. The data from your WordPress will be provided in JSON format. You can choose any programming language which can make HTTP request and interpret JSON can use the API. The REST API is used to interact with WordPress. Some languages are PHP, Java, Swift, Kotlin, Node.js, etc…
Vanilla JavaScript and jQuery can also fetch data through the API.
What is REST API:
An API is an interface that helps to fetch some data from the server and it also can update our database using API.
REST API: REST API is less robust than the alternatives. It is relatively simple and flexible. REST API deals with these 4 HTTP requests.
- GET
- PUT
- POST
- DELETE
Fetch Basic Data: To fetch some basic information from WP-JSON you just do a get request.
If you want to get information on your webpage then please use JSON Viewer Extension on your chrome browser. This extension helps to structure the data into JSON format.
The URL for accessing different types of data through WP-JSON are:
// Access the complete resource of wp-json <domain_name>/<wp_installation_dir>/wp-json/ // Get the list off all registered users <domain_name>/<wp_installation_dir>/wp-json/wp/v2/users/ // Get the details of any specific user <domain_name>/<wp_installation_dir>/wp-json/wp/v2/users/<userid> // Get the list of all published posts <domain_name>/<wp_installation_dir>/wp-json/wp/v2/posts // Get data about any specific post <domain_name>/<wp_installation_dir>/wp-json/wp/v2/posts/<post_id> // Get List of all published pages <domain_name>/<wp_installation_dir>/wp-json/wp/v2/pages
<wp_installation_dir> means the directory where the WordPress is installed. If you installed WordPress on your root directory then URL will be <domain_name>/wp-json/
There are so many tools in the WordPress plugin page that can disable the WP-JSON functionality from your WordPress site. If you don’t want to use it then it’s good to disable this.
WP-JSON functionality can be extended by different types of plugins. Like if you are using the WooCommerce plugin then many more things are available through the API. Disabling WP-JSON is not good for your site because many plugins use this feature to access the site information.
I hope I cleared your all doubts on WP-JSON. If you still have any doubt then please comment below.