Developing a WordPress REST API App: Getting Started

Share this article

Developing a WordPress REST API App

Key Takeaways

  • The WordPress REST API is an important tool for developers to interact with WordPress sites, allowing them to create, read, update, and delete data using HTTP requests. This opens up new possibilities for WordPress development, including creating mobile apps, custom admin interfaces, and integrating with third-party services.
  • The series covered in this piece aims to provide a hands-on learning experience for those with a non-technical background. It will guide users through the process of using the REST API to build a simple JavaScript app, powered by WordPress content, and using Facebook’s React library to display it.
  • The REST API is already being used by major sites worldwide and is set to become more mainstream in the WordPress world. Now is the time for developers and site owners to embrace this technology, as it is likely to define the future development of their sites.

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.

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.

Frequently Asked Questions about Developing a WordPress REST API App

What is the WordPress REST API and why is it important?

The WordPress REST API is a feature of WordPress that provides a standardized interface for interacting with WordPress sites. It allows developers to create, read, update, and delete data from a WordPress site using HTTP requests. This is important because it opens up a whole new range of possibilities for WordPress development, including creating mobile apps, custom admin interfaces, and integrating with third-party services.

How do I get started with the WordPress REST API?

To get started with the WordPress REST API, you first need to have a WordPress site set up. From there, you can access the API by making HTTP requests to the appropriate endpoints. You can use any HTTP client to make these requests, but many developers prefer to use tools like Postman or Insomnia for testing and development.

What are the different types of requests I can make with the WordPress REST API?

The WordPress REST API supports four main types of requests: GET, POST, PUT, and DELETE. GET requests are used to retrieve data, POST requests are used to create new data, PUT requests are used to update existing data, and DELETE requests are used to remove data.

How do I authenticate with the WordPress REST API?

Authentication with the WordPress REST API can be done in several ways, depending on your needs. For simple read-only requests, no authentication is required. For more complex requests, you can use cookie authentication, OAuth, or application passwords.

Can I extend the WordPress REST API to support custom functionality?

Yes, the WordPress REST API is designed to be highly extensible. You can add custom endpoints, modify existing endpoints, and even create entirely new APIs using the same underlying infrastructure.

What are some common use cases for the WordPress REST API?

The WordPress REST API can be used for a wide variety of purposes, including creating mobile apps, building custom admin interfaces, integrating with third-party services, and more. It’s a powerful tool that can greatly expand the capabilities of your WordPress site.

How do I handle errors with the WordPress REST API?

The WordPress REST API provides detailed error messages in the response body when something goes wrong. These messages can help you diagnose and fix issues quickly and efficiently.

Can I use the WordPress REST API with a non-WordPress site?

While the WordPress REST API is primarily designed to work with WordPress sites, it’s possible to use it with non-WordPress sites as well. This requires some additional setup and configuration, but it can be a powerful way to integrate WordPress functionality into other platforms.

What are the security implications of using the WordPress REST API?

Like any API, the WordPress REST API can potentially be a target for malicious activity. However, WordPress has implemented a number of security measures to help protect your site, including requiring authentication for sensitive operations and providing detailed control over what data can be accessed.

Where can I find more resources to learn about the WordPress REST API?

There are many resources available to help you learn about the WordPress REST API. The official WordPress developer documentation is a great place to start, and there are also many tutorials, blog posts, and online courses available.

Tom EwerTom Ewer
View Author

Tom Ewer is the founder of Leaving Work Behind and WordCandy. He has been obsessed with WordPress since he first laid eyes on it, and has been writing educational and informative content for WordPress users since 2011. When he's not running his businesses, you're likely to find him outdoors somewhere – as far away from a screen as possible!

WordPressWordPress REST APIWordPress-hubWordPress-tutorialsWP-API
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week