Let's Learn About the WordPress REST API

Included (partially) in WordPress 4.4!

Matt Banks / @mattbanks

December 10, 2015

mattbanks.json


{
  "name": "Matt Banks",
  "work": "@OddNetworks",
  "role": "Engineer",
  "development": [
    "JavaScript", "WordPress",
    "Xbox One", "iOS"
  ],
  "hobbies": [
    "playing with my sons",
    "video games", "soccer"
  ],
  "facts": [
    "tabs are better than spaces",
    "Slack is better than Flowdock"
  ]
}
									
Matt Banks

What is a REST API anyway?

REST stands for Representational State Transfer

A REST API provides a way to access, create, modify, and delete data from an external source

Separates the client from the server

CRUD - Create, Read, Update, Delete

otherwise known as PUT, GET, UPDATE, and DELETE

Beginners Guide from Tuts+

History of the WordPress REST API

Began as a Google Summer of Code project

Made to replace the aging, not-so-fun-to-use XML-RPC

Make WordPress a solid application framework

Amazing work from Ryan McCue, Rachel Baker and everyone involved

Infrastructure integrated into Core this week!

Let's Install WordPress REST API

Step 1: Upgrade to WordPress 4.4

But you already did that, right?

Step 2: Install the plugin

Step 3: ???

Step 4: Profit

Ok, now what?

Demo

Advanced Usage

Install the Client JS plugin to give you helper methods out of the box

Building custom endpoints lets you respond with any data you need

Authentication

Cookie authentication

OAuth1 (via plugin)

OAuth is complex, but the plugin is hoping to simplify application management and setup with a full admin UI

A few limitations

Serialized data cannot be read or stored using the REST API

Protected meta (prefixed with an _) cannot be accessed by the API

Most custom fields from plugins aren't immediately visable over the API (but they can be!)

What kind of awesome things are using REST API's?

What can we build with this now that we have it at our fingertips?

Calypso

Calypso screenshot

Overdog

Overdog screenshot

Links and Useful Tools

WP REST API Documenation

Postman REST Client (Chrome App, Mac App coming soon)

Using the WordPress REST API from SitePoint

Questions?

Matt Banks

mattbanks.me | @mattbanks | matt@mattbanks.me
github/mattbanks