Developing a WordPress REST API App: Getting Started

This article on developing a WordPress REST API app was originally published by Torque Magazine, and is reproduced here with permission.

Excitement over the WordPress REST API has been building for what seems like an eternity, but we’re still pretty much at the starting gate in terms of what it’s actually going to mean for site owners and developers once it finally lands.

Though I’ve written extensively about the potential implications of the REST API, I’ve been holding back on actually diving in and getting my hands dirty to date. With the REST API finally taxiing on the runway, now seemed a great time to grasp that nettle and really start digging into detail.

--ADVERTISEMENT--

Over the course of this series, I’ll be taking the new hotness for a spin by putting together a simple JavaScript app that uses the REST API to power its content. It promises to be an intense learning experience, but one that will hopefully serve others who are coming from a non-technical background as well.

A Brief Note on My Background

Though WordPress has long been a passion of mine, I’m a writer and entrepreneur by trade. I can’t pretend to be coming at this project from any type of serious development background. “Knows just about enough to be dangerous” would be how I’d charitably classify my coding experience to date.

So, this series won’t be quite the deep dive you might expect from a theming professional such as Jack Lenox, or a senior web developer such as Ramsay Lanier. It should also be no great surprise that I’m not approaching this from the point of view of an established top-tier digital agency looking to kick the tires of the latest technology.

Major agencies such as Modern Tribe are already working with the REST APIMajor agencies such as Modern Tribe are already working with the REST API

Nope, this series will be much more along the lines of an average WordPress user looking to get to grips with the next generation of the platform via a practical, exploratory project.

Hopefully that’s an approach that will also resonate with a significant percentage of other site owners out there. Put it this way – if your eyes instantly start to glaze over at the introductions of other (admittedly excellent) tutorials such as the one below, this is the series for you:

In the following weeks, through a series of articles, I’ll explain how I’m using Node.js and Express on the backend with a GraphQL server hooked up to a MYSQL WordPress database that uses Apollo to fetch data and pipe it into React components. Don’t worry, I’ll still be using the tried and true WordPress admin interface.

With those caveats out of the way, let’s briefly recap why now is a great time to be really rolling up your sleeves and using the REST API in earnest.

Why Now Is the Time to Embrace the REST API

The launch of Calypso and Matt Mullenweg’s State of the Word address back in late 2015 made it crystal clear which way the wind is blowing in the world of WordPress at large. To put it in a nutshell, the REST API is going to be at the centre of the next stage of the platform’s future, and developers are going to have to get on board with JavaScript sooner rather than later.

The arrival of Calypso points the way to the future of WordPress

We’ve already seen entire conferences devoted to exploring the implications of the REST API, and increasingly large real-world projects basing themselves around it, despite its late arrival. From Microsoft to the New York Times, blue-chip companies worldwide are chomping at the bit to really explore its power.

If you’re a theme or plugin developer, you can rest assured that the vast majority of your competition are already, at the very least, actively researching the topic. If you’re a site owner, you can expect the next five years or more of your site’s development to be significantly defined by the possibilities that the REST API opens up. No matter what way you look at it, now is the time to get on board this particular train.

What We’ll Be Looking to Do in This Series

In this series, we’re going to start from scratch with a local install, and use WordPress to house a collection of quotes from a great American original — Mr. Henry David Thoreau. With our words of wisdom safely stored in the WordPress back end, we’ll be looking at interacting with them via the REST API, and building out a simple JavaScript-powered front end to display them in a variety of ways using Facebook’s React library.

We’ll be using the current plugin version of the REST API

Along the way, we’ll touch on subjects such as alternative front end solutions, integration with mobile apps, design tips and tweaks, and experimenting with third-party APIs for added functionality. By the time we’re finished, you should have a much more grounded and practical view of what the REST API is actually all about.

We’ll be using WordPress 4.5.3 running on a local development environment, version 2 of the REST API as a plugin, React, and a whole lot of patience and persistence to put together our finished project. Stick along for the ride and you’re sure to pick up a ton of useful info along the way!

Conclusion

The tools to get cracking with the REST API already exist, it’s used in production by several major sites worldwide, and it won’t be long until it hits the mainstream WordPress world in earnest. There’s simply never been a better time to learn about it.

Aimed at a relatively non-technical audience, our series on developing a REST API app from scratch will take you from zero to hero in no time at all. You won’t need a computer science degree to follow along – just a little time, patience and perseverance.

Stay tuned for part two, in which we’ll fire up our local site, get some data into it, and start looking at basic reading and writing functionality via the REST API.

You can read the other articles in this series here.