Slide 1

Slide 1 text

The WordPress
 JSON REST API WordCamp NYC 2014 Ryan McCue @rmccue

Slide 2

Slide 2 text

wp-api.org

Slide 3

Slide 3 text

Meet the Team

Slide 4

Slide 4 text

What is the REST API?

Slide 5

Slide 5 text

Three Parts:
 “JSON REST API”

Slide 6

Slide 6 text

JSON { "ID": 4, "title": "My Awesome Post", "content": "This is my awesome content!" } JavaScript Object Notation • Supported by basically everything • Human readable • Standard

Slide 7

Slide 7 text

REST Actions applied to Resources Create POST Read GET Update PUT Delete DELETE Uses HTTP actions: Representational State Transfer

Slide 8

Slide 8 text

REST Representational State Transfer /posts /posts/4 /posts /posts/4 /posts/4 GET GET POST PUT DELETE Action
 (Verb) Resource
 (Object)

Slide 9

Slide 9 text

API Application Programming Interface A way to access and manipulate your data

Slide 10

Slide 10 text

API Or extend as needed! GET POST PUT DELETE Posts ✔ ✔ ✔ ✔ Pages ✔ ✔ ✔ ✔ Custom Post Types ✔ ✔ ✔ ✔ Post Meta ✔ ✔ ✔ ✔ Media ✔ ✔ ✔ ✔ Comments ✔ ✔ Taxonomies/Terms ✔ ✔ ✔ ✔ Users ✔ ✔ ✔ ✔

Slide 11

Slide 11 text

Why do we need it?

Slide 12

Slide 12 text

XML-RPC Hugely complicated: (WordPress for iPhone Trac)

Slide 13

Slide 13 text

Jetpack API Easy for developers Works with Javascript easily (JSON-based)
 Requires Jetpack active Depends on WordPress.com Does not work for local development Cannot control access to certain apps

Slide 14

Slide 14 text

How do we use it?

Slide 15

Slide 15 text

{ "name": "WP API Dev", "description": "Just another WordPress site", "URL": "http://local.wpapi.dev", "routes": {}, "authentication": [], "meta": {} } /wp-json/ GET

Slide 16

Slide 16 text

[{ "ID": 110, "title": "Testing sticky", "status": "publish", "type": "post", "author": {}, "content": "

this should be stuck as a post. Stuck on you.

\n", "link": "http://local.wpapi.dev/testing-sticky/", "date": "2014-06-02T10:47:39-05:00", "modified": "2014-06-02T10:47:39-05:00", "format": "standard", "slug": "testing-sticky-2", "guid": "http://local.wpapi.dev/testing-sticky-2/", "excerpt": "

this should be stuck as a post. Stuck on you.

\n”, "comment_status": "open", "sticky": true, "meta": {}, "featured_image": null, "terms": {} }] /wp-json/posts GET

Slide 17

Slide 17 text

{ "ID": 1, "title": "Hello World!", "status": "publish", "type": "post", "author": {}, "content": "

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

\n", "link": "http://local.wpapi.dev/hello-world/", "date": "2014-04-18T15:14:46-05:00", "modified": "2014-05-02T01:26:30-05:00", "format": "standard", "slug": "hello-world", "guid": "http://local.wpapi.dev/?p=1", "excerpt": "

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

\n", "comment_status": "open", "meta": {}, "featured_image": null, "terms": {} } /wp-json/posts/1 GET

Slide 18

Slide 18 text

How can we use it?

Slide 19

Slide 19 text

Install the Plugin

Slide 20

Slide 20 text

Backwards Compatible Right Now: Version 1 Coming Soon: Version 2 Full Compatibility

Slide 21

Slide 21 text

Where can we learn more?

Slide 22

Slide 22 text

Resources JSON REST API Plugin:
 github.com/WP-API/WP-API ! OAuth1 Authentication Plugin: 
 github.com/WP-API/OAuth1
 Basic Authentication Plugin: 
 github.com/WP-API/Basic-Auth ! API Console:
 github.com/WP-API/api-console JSON REST API

Slide 23

Slide 23 text

Resources JS Client:
 github.com/WP-API/client-js ! PHP Client: 
 github.com/WP-API/client-php 
 WP-CLI Client: 
 github.com/WP-API/client-cli JSON REST API Clients

Slide 24

Slide 24 text

Have questions? Ryan McCue @rmccue wp-api.org github.com/WP-API/WP-API speakerdeck.com/rmccue/wcnyc2014