Development

WP REST API


Using WordPress as a content API

WordPress may not seem like the missing piece of your content-needs puzzle. The old built-in API is based on a protocol that is nearly 20 years old. It can be difficult to work with on modern platforms that have an easier time parsing JSON data.

The WordPress REST API, however, is a great alternative and the ideal agnostic back-end for developers with content-publishing needs—and works to ensure that whatever your project is, it stays current with the ever-changing nature of web. As of WordPress 4.4, the REST API (formerly a separate plugin) is being merged into the WordPress core. Here’s why we like the REST API, with some ideas on how (and why) you can incorporate it into your next project.

Illustration of a content API and various sources pulling from it
Illustration by Maggie Famiglietti

Say you’re building an app with Ruby on Rails and your content producers need to publish regular updates through it. You could switch gears and spend precious time learning the ropes of WordPress (or build out a completely new content management system) to do this. Or, you could utilize the REST API, which pulls content from the database and into your app. This latter option saves both time and sanity. It keeps both the updates flowing and your team’s developers focused on the task at hand: working with Rails (rather than busying themselves with PHP) or staying focused on iOS (rather than reinventing the wheel and building a new CMS) to create the next world-changing app.

It’s an idea that can be applied to different kinds of projects, too. Think of it as the best of both worlds—the ability to create front-end templates in your programming language of choice and the ubiquitous, powerful WordPress back-end. It’s keeping the focus on building powerful web and mobile apps. Studying up on WordPress is not necessary.

Using the WordPress API—either our recommended WP REST API or the older-school XML-RPC—is easy, through existing libraries from example projects. Of course you can start your own, but if you find your preferred language here, you’re ready to get cracking:

REST API

NodeJS

For node and the REST API there’s wordpress-rest-api, which is under development and fairly well documented. If you need to grab specific sets of posts:

Python

For Python and the REST API there’s wordpress_json, a lightweight Python wrapper for the API. Getting posts is as easy as

AngularJS

And AngularJS developers can utilize the AngularJS Module for WP-API. There’s a dependency, another module called ngResource, but once you’re up and running, grabbing post data is as simple as:

The Rest API team has put together a solid list of resources as well.

Besides saving task-focused developers some time and potential frustration, there’s a bigger picture with using a content API. UX and content strategy guru Karen McGrane has been expertly preaching about the oncoming content zombie apocalypse: as new platforms continuously emerge and new screens are rendered invaluable, websites that can’t adapt to or keep up with the movement will be left in the dust. That’s where content APIs figure in. The agnostic back-end makes it much easier to adapt to new tech—so you can better keep pace with the ever-changing content landscape.

There’s an easier way to publish content and keep your focus on staying current with technology as it constantly evolves: WordPress’s REST API.

Want to tell us what you think? Contact or hire us!