WordPress REST API

What is the WordPress REST API?

If you’ve been following the ins and outs of WordPress core development for the last couple of years you may have heard talk of the WP API or the WordPress JSON rest API or JSON API or something similar. The WordPress REST API is a RESTful API that can be accessed simply through HTTP requests to access the data on a WordPress site in JSON format.

In plain English – the WordPress API is a new way of accessing the data WordPress provides without having to go through a theme, or a RSS feed, or XML-RPC. And accessing doesn’t just mean getting the data to read. With the WP API you’ll be able to create, read, update, and delete content in the WordPress database without interacting with WordPress directly.

Up until now if you wanted to read a WordPress post or page you had to use a WordPress query in PHP typically through a WordPress theme. The theme would use the WordPress templating engine and hierarchy, otherwise known as a theme, to output the post or page or other content you requested through the address bar on your browser. This set up had some severe limitations. If for example, you wanted the content from your WordPress site to appear in a mobile app you would have to either build a custom PHP application to do it or pass the data through antiquated protocols.

With the WP API we can bypass this entire process. Getting the data from a WordPress site using the API is as simple as submitting a standard HTTP request or URL. Once you have that data you can use any application or programming language to do whatever you want with it. So, you can build WordPress sites using PHP or you can build them using JavaScript or Ruby or Objective-C or whatever you want. The WP API gives you direct access to the data and allows us to do whatever we want with it.

The WP API also allows you to access and edit the data in the database without going through WordPress Admin. (This is only possible if you have the right security credentials so your data is not at risk.) But it means you can now build new interfaces for creating content with WordPress.

For more information you can go to the WordPress REST API page on WordPress.com. You can also find out how to interact with the rest API by going to: v2.wp-api.org The API project is hosted on GitHub: github.com/WP-API /WP-API