The WordPress REST API is a BFD.
Hailed as potentially the most exciting project for the platform since custom post types were introduced back in 2009, it’s safe to say the WP REST API is a huge step toward securing WordPress’s future as a fully-fledged application framework.
In a nutshell, the WP REST API enables developers to decouple the front-end from the core WordPress software. Already, this is leading to better mobile and desktop apps and highly customized websites that look nothing like WordPress.
In this post, we’ll recap on what the WordPress REST API is, explore its current development, and take a look at how some websites and projects are using the API in clever ways we previously only could have imagined and helping WordPress evolve.
What is the REST API?
The REST API brings the content of any WordPress website into an easily-consumed API (API is short for Application Program Interface, BTW), basically allowing the CMS to serve as a storage and retrieval system for publishing content on the web. You can grab your site’s data in simple JSON format, including users, posts, taxonomies and more. Retrieving or updating data is as simple as sending an HTTP request.
If you’re new to the WordPress REST API (I’m assuming you know something about it since you’re reading this article!) and you are still trying to understand how it all works, then you might want to check out this fantastic guide that breaks down what the abbreviations mean to better explain how the API works.
The REST API project was borne out of necessity. As WordPress moves towards its inevitable future as an application framework, new APIs were needed, and the REST API creates an easy to use and understand framework for creating these APIs, and also creating APIs for WordPress core.
The project originally began as a feature plugin for WordPress. WordPress 4.4 included the initial infrastructure of the REST API, while the endpoints for the project didn’t appear until WordPress 4.7. This essentially gave the project’s development team time to test the functionality that powered the API without actually exposing the data itself.
Around 28% of all websites use WordPress, and the front-ends of these sites are built with PHP and the WordPress theme system. The REST API, however, frees developers from having to use the WordPress front-end at all – they can now access data from a WordPress website and display it using the technology of their choice, whether it’s for a website, Android application, iOS application or other technology.
The Current Development of the REST API
There are three main focuses for the development of WordPress core this year: the REST API, the Editor, and the Customizer. While there aren’t any significant advances for the REST API in this week’s release of WordPress 4.8, the users endpoint is expected to be improved for Multisite configurations, providing compatibility with how users are currently managed in a network.
However, we can expect to see more advances in the REST API in upcoming releases of WordPress in 2017. According to Matt Mullenweg, the plan is to work on getting first-party wp-admin users of the new endpoints and, hopefully, replace all the core places where admin-ajax is still used. Developers Ryan McCue and K.Adam White are taking the lead on Mullenweg’s objectives, as well as infrastructure and endpoint performance, security, and improvements to authentication options and documentation.
While there have been big advancements for the REST API in previous versions of WordPress, in particularly WordPress 4.7, look out for more in WordPress 4.9 and 5.0.
Agencies and Projects Taking WordPress to a Whole ‘Nother Level with the REST API
Digital agencies are driving the use and development of the REST API, taking the lead in finding cool and clever ways to implement it. Here are some exciting real-world examples:
The Solomon R. Guggenheim Foundation and museum’s website is a “headless” version of WordPress with content served via the REST API.
According to Matt Johnson, CTO of Alley Interactive, the agency that built the site, the defining feature of the project was the decision to build a single-page application experience using Angular, which called for a major departure from how the agency had traditionally built WordPress sites.
Johnson has provided more details about the project and a look under the hood on the Alley Interactive website, while Laura Kleger, Guggenheim’s interactive director, has written a very informative post about the redesign’s complex agenda.
New York Times
According to NY Times developer Scott Taylor, WordPress serves as the backend for the live blog with a custom-built Backbone-based editor. Content created this way is served to a WordPress front-end that is rendered via React.js. This setup is “now the de facto platform for breaking news at The New York Times.”
Like the New York Times, Wired uses the REST API to power its live blog, allowing reporters to quickly file live updates from Slack. According to Jake Spurlock, a software engineer at Wired, “there are lots of interesting things you can do when you start combining different technologies like [WordPress and Slack].”
The Wired website also uses the REST API to serve content to the Apple News app. Like many news sites, Wired displays sponsored stories at the bottom of its articles and uses Outbrain, a third party service, to do this. However, Wired uses the REST API as a fallback option if Outbrain goes down or isn’t feeding links to its site.
Digital product studio ustwo’s website features a WordPress backend and a React-built front-end. The single-page site uses React to allow for isomorphic rendering (pages can be rendered on the server or by the client). There’s also a Node.js server that enables server-side rendering. Meanwhile, on the backend, authors use a custom page builder plugin to enter content. The infrastructure for the REST API is used along with a custom API comprising custom endpoints that deliver content in JSON format to the front-end.
Other websites and agencies using the REST API include:
- npm, a packet manager for Node.js, uses the REST API for security reasons as it wanted a secure want to deliver content to different areas of the page without having to access IP addresses that aren’t whitelisted. Their site is built using JSON with Handlebars templates to deliver content. The REST API doesn’t just send content to the site: it also sends rendered HTML, scripts and stylesheets.
- Event Espresso, a popular event management plugin, uses the REST API to provide access to its data.
- Editus, a front-end editor for WordPress, uses the REST API to save posts and improve compatibility with websites that use security features.
- The WP Live Search plugin uses the REST API, in combination with Backbone.js and Underscore.js, to deliver live search results as a user types a search query.
- Digital agency Modern Tribe rebuilt its website with React and the REST API.
- StoryCorps, a website and app that makes it easy for to anyone with a smartphone to record an interview and publish it, is built on WordPress and uses the REST API to enable access to a customized content architecture.
What’s coming up next for the REST API?
Now that the REST API’s endpoints are part of WordPress core and the API has been merged into WordPress for good, more and more developers are recognizing that they don’t have to use the WordPress front-end – it’s now optional.
In its REST API white paper, Human Made predicts an emergence of REST API base themes that rebuild WordPress features on the front-end. These boilerplate themes would be written in different languages and provide a starting point for front-end developers to build on.The agency also predicts that we’ll soon see admin-ajax replaced in favor of the REST API, increasing the speed of basic functions like editing menus or publishing posts. This could potentially go hand-in-hand with the WordPress project’s increased focus on improving the WordPress Customizer and Editor as the user-friendly starting points for users new to WordPress.
Already, we’re starting to use WordPress without even visiting it. And as development of the REST API continues, more sites and services are connecting WordPress with other technologies, taking the CMS further away from its origins as a blogging tool, ensuring the WordPress of the future will be no doubt be unrecognizable from the WordPress we know today.