Slide 1

Slide 1 text

THE WORDPRESS REST API

Slide 2

Slide 2 text

@jacklenox

Slide 3

Slide 3 text

WHAT IS A REST API?

Slide 4

Slide 4 text

REST API • REST stands for REpresentational State Transfer • API stands for Application Programming Interface • Probably the optimal word in all of this is Interface • A REST API gives you a new way of accessing your blog/site’s data

Slide 5

Slide 5 text

The PHP API • Gives you ‘the loop’ • the_post(), the_title(), the_content(), the_date() etc etc. • It’s how developers have interacted with WordPress since day one • The problem here is that you pretty much have to use PHP

Slide 6

Slide 6 text

THE REST API GIVES US OPTIONS

Slide 7

Slide 7 text

HOW?

Slide 8

Slide 8 text

A sample request

Slide 9

Slide 9 text

The WordPress REST API • Several have popped up over the years • The now-official WordPress.org one has been forked from a plugin called ‘JSON API’ • This was first released in the plugin repository in 2009 • It was built as part of a project for the MoMA in New York. The project used Ruby on Rails. They had a Ruby on Rails frontend and a WordPress backend. • Due in WordPress core at some point (hopefully this year)

Slide 10

Slide 10 text

SO WHY THE WAIT?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

JavaScript has gotten HUGE • Node.js & npm • Backbone • Angular • Ember • React

Slide 13

Slide 13 text

– Trek Glowacki, Core Team, Ember “Since the start of the web, for every interaction there have been two supercomputers involved. The supercomputer sitting in front of you and the supercomputer in a data centre somewhere. We have barely begun to take advantage of that supercomputer sitting in front of you.”

Slide 14

Slide 14 text

SPAS SINGLE PAGE APPLICATIONS

Slide 15

Slide 15 text

What is an SPA? • As opposed to multipage web application • Has only one initial page load • When done well, provides a more continuous, fluid user experience

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

The times are a-changin’ • This is nothing new • WordPress themes and plugins have been steadily doing more and more • It is relatively straightforward to have SPA elements within a multipage web application • Backbone has been included in WordPress core since 2012

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

So what can I actually do with the REST API? • REST APIs centre around a series of verbs • GET, POST, PUT, DELETE • GET posts/pages/comments etc. • Edit and add posts/pages/comments via POST • DELETE posts/pages/comments etc.

Slide 20

Slide 20 text

It’s extensible

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

FIN

Slide 24

Slide 24 text

Useful links… wp-api.org github.com/WP-API/WP-API