Using WordPress as an API

Using WordPress as an API

Wait, what’s an API and why would I use WordPress as an API?

What the heck is a BYOFE, and what does it have to do with WP?

Why are there so many acronyms?!?! 😉

WordCampEU 2022

Workshop Prerequisites

  • Probably your own laptop to work along
  • Refer to or download this Git repository.
  • Install, cross platform, available for Linux, Windows, and Mac
  • Postman app or Insomnia app installed, cross platform, available for Linux, Windows, and Mac (or you can use the web version of Postman.
  • Knowledge and experience with Git, PHP, and maybe some JS
  • LocalWP (from, or a similar local development environment, but I won’t be helping debug it so they should install and test it before they come)
  • Postman ( they can download the app or use the web app. The need create an account. (preferred, I’ll be using this in the workshop)
  • Insomnia ( )
  • Extra Credit: NodeJS installed for the feed reader.

It would be good if you were familiar with at least PHP and JS (you don’t have to be experts, I think intermediate is fine, there will be code they can copy/paste). If they were familiar with Git and Github, that would be good too.

Workshop Outline

  1. Setup, import, first example (10 minutes)
  2. WP REST API (30 – 40 minutes)
    1. GET and POST with posts/pages
    2. CPTs
    3. Meta, ACF
    4. Custom endpoints
  3. Authentication methods (20 minutes)
    1. None (already covered)
    2. API Key/APP Password
    3. JWT
  4. Repeat some of the above with with WPGraphQL (15 minutes)
  5. Postman (10 minutes)
    1. Collections
    2. Tests
  6. Extra Credit (15 minutes)
    1. Set up basic React app
    2. “Feed Reader”
    3. JWT Login and Auth for creating post types.

In 2020, I gave a different version of this talk to our local WP meetup via Zoom or Google or whatever we were using in those “early pandemic days”… Below are the abstract, recording, and slides for that presentation…

WordPress is an incredibly flexible platform on which to build websites and web apps. Traditionally, WP has been used for blogs, publishing platforms, business websites and more. It offers an all-in-one package.

But what if you want to use a framework like Gatsby (or Gridsome), NextJS (or NuxtJS), 11ty, MERN, Laravel, Ruby on Rails, RedwoodJS, etc. to build an application, but long for the WordPress editing experience?

Or, what if you have a client that already has a web application running, and would like to incorporate a blog using WordPress to that application?

There are many ways to “couple” other technologies with a “decoupled” WordPress publishing experience.

In this talk, we’ll explore:

  • What an API is and to use WordPress as an API
  • Look at other BYOFEs (bring your own front-end), and how WordPress offers the same or more out of the box
  • How we can easily create custom post types and custom fields to manage our data in WordPress for API consumption
  • How we can use other frameworks to read and publish WordPress data (I’ll be using examples from Create React App and Gatbsy mostly, but this will apply to any framework that can consume an API
  • Some caveats and how to address those.

This will be a jam-packed, Jam-stacky talk, so BYO-lunch and BYO-curiosity as we discover how we can use WP as an API instead of other BYOFE (ok, I’ll stop with the acronyms now!).

Presentation Slides

0 responses to “Using WordPress as an API”