Slide 1

Slide 1 text

The WordPress REST API A game changer for WordPress @ #wcgva

Slide 2

Slide 2 text

27.1% of The Web Now available in a RESTful way.

Slide 3

Slide 3 text

Silvan Hagen Co-Founder & WordPress Developer @wearerequired @neverything

Slide 4

Slide 4 text

What is A REST API? Trust me it’s easier than it sounds.

Slide 5

Slide 5 text

REpresentational State Transfer - Not any smarter yet? Well me neither ¯\_(ツ)_/¯ - It’s about resources & a little bit about verbs - Uses HTTP methods in a specific way

Slide 6

Slide 6 text

REST: Let’s have a look GET /friends => Returns a Collection of friends GET /friends/joe => Returns a single friend GET /friends/new => Could be a form to add a friend

Slide 7

Slide 7 text

The HTTP methods in REST GET /friends => READ POST /friends => CREATE PUT /friends => UPDATE DELETE /friends => DELETE The famous CRUD

Slide 8

Slide 8 text

What about REST and WordPress? GET /wp-json/wp/v2/posts => Collection of Posts GET /wp-json/wp/v2/posts/ => Singular Post GET /wp-json/ => Allows discovering the API

Slide 9

Slide 9 text

REST & WordPRESS A little history lesson about the REST API.

Slide 10

Slide 10 text

How did we get here? - Started as GSoC project in 2013 by Ryan McCue - Infrastructure merged into WP 4.4 in 2015 - Content Endpoints merged into WP 4.7 in 2016

Slide 11

Slide 11 text

What’s in it? There are a few more concepts in the WP REST API.

Slide 12

Slide 12 text

API Discovery via Response Header - In the response header of a request: Link: ; rel="https://api.w.org/"

Slide 13

Slide 13 text

API Discovery via Element - Added to the of your HTML:

Slide 14

Slide 14 text

API Feature Discovery - Authentication - The API will tell you how to authenticate

Slide 15

Slide 15 text

API Feature Discovery - Extensions - The API will tell you what namespaces exist:

Slide 16

Slide 16 text

API Feature Discovery - Combined

Slide 17

Slide 17 text

API Routes

Slide 18

Slide 18 text

API Routes

Slide 19

Slide 19 text

Linking using HAL - Uses HAL (Hypertext Application Language) to link related resources

Slide 20

Slide 20 text

Embed Related Resources - Add ?_embed to any API Request URI

Slide 21

Slide 21 text

Relax: The Crazy Part is over, let’s look at Examples

Slide 22

Slide 22 text

What Can You Build? A few examples and ideas.

Slide 23

Slide 23 text

In The WP-Admin https://wordpress.org/plugins/dashboard-directory-size/

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

In Your Theme

Slide 26

Slide 26 text

Standalone Web Apps/Sites

Slide 27

Slide 27 text

DATA Heavy Things

Slide 28

Slide 28 text

APPS APPS APPS https://github.com/joehoyle/vienna

Slide 29

Slide 29 text

So are you ready for the WP REST API?

Slide 30

Slide 30 text

Already Built Something?

Slide 31

Slide 31 text

Some more Ideas - Mobile Apps - Other technologies can consume WP in a standardised way - New Admin Interfaces - Meta Boxes in the backend - All the lame admin-ajax.php stuff - WP_List_Tables - Customizer - Data heavy widgets - Comments (cool once comment type is merged) - Links & more: https://goo.gl/N4RQ6N

Slide 32

Slide 32 text

Thanks for Having Me! Questions?