Getting Ready for the WordPress REST API
If you have been following WordPress news for the last year or so, you’ve probably heard of the WordPress REST API. In fact, it’s hard not to hear about it. Take a look at the schedule of a recent WordCamp, and you’re almost guaranteed to find a talk about the REST API. There’s no doubt it’s the most exciting feature to come to WordPress in a while, but if you’re not familiar with the REST API, you might be wondering what all the hoopla is about.
What is the WordPress REST API?
First of all, API stands for Application Programming Interface. It’s basically a fancy name for a set of rules for how software components interact with each other. It tells software applications how to retrieve and input data. For example, your Twitter widget makes calls to the Twitter API to get the right set of tweets that belong to you so that you can display it on your website. The REST (which stands for Representational State Transfer) API is just a special kind of approach to APIs. It usually involves four different kinds of methods:
GET (get data),
PUT (replace data),
POST (create data), and
DELETE (delete data).
So what does this all mean? This means that the REST API provides me specific rules to make a
GET request. I can type in
example-site.com/wp-json/wp/v2/posts and get back pure, unadulterated data about all of the site’s posts. This, of course, assumes that the site has the REST API plugin installed or is running the right version of WordPress when the REST API is merged into core. The JSON data that is returned is quite important, because this means your data is now highly portable and accessible on different platforms (more on that in a bit).
What Can I Do With It?
Throwing around all these capital letters don’t mean much unless we know what to do with it. Why are people so excited about it? What are the possibilities? I’m glad you asked. There are three important features about the WordPress REST API that open the platform to new possibilities.
1. Your data is portable
With the WordPress REST API, your content escapes their PHP prison that is required to run WordPress. The simple JSON data format means your data can be read by all sorts of different programming languages and platforms. Most importantly, your data is now a lot friendlier to mobile platforms. Imagine a mobile app developer being able to get the title and content of your latest post without having to deal with all the extra HTML on your website. This makes his/her job a lot easier when coding an app that uses your content.
2. Themes are optional
3. The admin dashboard is optional, too
Remember how the REST API allows you to
DELETE data? This means that you can create and edit posts without visiting the WordPress admin. This has huge implications for mobile applications — we can now build apps that interact with a WordPress website.
I’m Sold. Where Do I Start?
Assuming that the REST API hasn’t made its way into the WordPress core yet, you’ll need the WordPress REST API plugin. There are more than one JSON API plugins out there, but the one that you want is here. Also keep in mind that the plugin and API architecture is changing, as version 2 is coming out and is on track to be merged into core.
To get a good overview of the REST API, you can check out the presentation by Rachel Baker over at WPSessions. The session is paid, but is well worth it. You can also check out WPEngine’s free guide to the REST API.
The WordPress REST API is evolving as it prepares for a merge into the WordPress core. But that doesn’t mean you can’t start playing around with it. It’s one of the most promising features to come to WordPress in a while, and getting ahead of the curve will only benefit you.