WordPress Rest API

20
Brian Layman eHermits Inc, LTD WordCamp Columbus August 27, 2016 A Quick Trip Down the Rabbit Hol

Transcript of WordPress Rest API

Page 1: WordPress Rest API

Brian LaymaneHermits Inc, LTD

WordCamp ColumbusAugust 27, 2016 A Quick Trip Down the Rabbit Hole

Page 2: WordPress Rest API

• Brian Layman• I work from home• I spend all day on the computer• All best my friends are online• I don’t hang out at parties• I spend my day in a cave like room• Yes, I am an eHermit

http://eHermitsInc.com

INTRODUCTION

Page 3: WordPress Rest API

http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png

OurDarkSecret

Page 4: WordPress Rest API
Page 5: WordPress Rest API

FUNDAMENTAL CHANGES IN WP• Plugins – Made WordPress extendable• The NONCE – WordPress is made safe.• Tags – Changed how we reached posts • Plugin & Theme Updates • Shortcodes• Automatic core security updates• Custom Taxonomies• Custom Post Types• Theme Customizer

Page 6: WordPress Rest API

THIS ONE IS DIFFERENT• WP-REST-API

• All Inclusive• Externally focused• Not just for us• Language independent• Driven not by community needs but by the direction the web is going• We can’t tell you what all changes this will bring.• This is the path to the next 15 years of WordPress

Page 7: WordPress Rest API

WP-REST-API - WHAT IS IT?• WordPress is moving towards becoming a fully-fledged application

framework, and we need new APIs. This project was born to create an easy-to-use, easy-to-understand and well-tested framework for creating these APIs, plus creating APIs for core.

• This plugin provides an easy to use REST API, available via HTTP. Grab your site’s data in simple JSON format, including users, posts, taxonomies and more. Retrieving or updating data is as simple as sending a HTTP request.

• The API exposes a simple yet easy interface to WP Query, the posts API, post meta API, users API, revisions API and many more. Chances are, if you can do it with WordPress, WP API will let you do it.

http://v2.wp-api.org/

Page 8: WordPress Rest API

OK, BUT WHAT IS IT?• An API is an Application Programmer’s Interface

• An API is a set way to allow other people to use the code that you’ve created.

• REST is Representational State Transfer• It basically is a “language” used to speak to websites using URLS• A collection of URLS through which you can explain

• What information you are seeking• What action you want to take• What information you already have and are providing to allow the request to be

complete

Page 9: WordPress Rest API

OK BUT WHAT ABOUT THE WORDPRESS PART OF IT

• Using URLS you can write an app that can do anything you can do in WordPress*

• There might be some lag between when new features get into Word• The most basic examples

• List all the posts• https://2016.columbus.wordcamp.org/wp-json/posts

• Get all the details about a post• https://2016.columbus.wordcamp.org/wp-json/posts/769

• Get all the details about an attachment• https://2016.columbus.wordcamp.org/wp-json/posts/965

• Get the hashtag for a WordCamp event• https://2016.columbus.wordcamp.org/wp-json/taxonomies/hashtag/terms

Page 10: WordPress Rest API

BUT WAIT THERE’S MORE• The previous page showed Getting information, but you can talk to the API

and do more than ask form information• You can GET, POST and DELETE

• /wp-json/<object> ~ /wp-json/posts• Get – Returns a collection• Post – Adds a new object

• /wp-json/<object>/<id> ~ /wp-json/posts/769• Get – Returns the specific object• Post – Updates a specific object• Delete – Deletes a specific object

Page 11: WordPress Rest API

WAIT!!! DID YOU JUST SAY DELETE?!?

• Yes, you can delete objects with the API.• No – the sky isn’t falling. • The WP-REST-API is safe and the same permissions you have when you

are visiting the website through the browser exist for when you visit the website through logging in (or not)

• In point of fact you still have to login or identify yourself in one of three ways

• A cookie • OAuth 1.0a (like connecting JetPack to Twitter)• Basic Authentication

• Sending a username and password with every request• Only do this with an https address

Page 12: WordPress Rest API

OK – HOW ARE WE DOING?

Page 13: WordPress Rest API

WHAT CAN YOU DO WITH THE WP-REST-API?

https://backpress.org/

• Anybody rememberBackPress?

• Core of WordPress without WordPress

• A huge leg up because authentication and everything else is already done.

• With the WP-Rest-API, this is a freebie

Page 14: WordPress Rest API

FOR USE IN THEMES• Several experimental themes already exist

• Picard • Tango - https://github.com/kwight/tango/

• Many other sites are implementing feature level support• Quartz

• http://qz.com• Speeds interface through pre-fetching posts and using the local storage feature

• New York Times• Live Event coverage

• Many SPA websites are coming

Page 15: WordPress Rest API

FOR USE ON DEVICES• Native phone applications

• Object-C or any other modern language can speak REST and JSON • Responsive themes can be step 1 for this to get your MVP

• Updates from your watch• Server Monitoring• Event Tracking

• Jogging routes• Smart House Integration• Webcam

Page 16: WordPress Rest API

DATABASE INTEGRATION• WordPress & Custom Post Types allow you to do more• Custom Post Types and the WP-Rest-API take you that much further again

• Video Warehouse – Apple TV powered by WordPress• Photo Albums• Ancestry and Family Tree Applications• Retail Stores

Page 17: WordPress Rest API

LEGACY/INDUSTRY CONVERSION• Because almost all coputer languages can speak REST this is a pathway

to get the data from these last millennium platforms into formats newer solutions can use.

• This is the source code needed for an IBM AS/400 to post to a REST API

• Now WordPress can be the conduit to track the productions of assembly lines.

• Dominoes Pizza can show your pizza being assembled. Maybe WordPressWill be used to show your as your Teslacomes through the production line.

Page 18: WordPress Rest API

GETTING CREATIVE• You aren’t limited to what WordPress does now.

• You can add custom routes & endpoints to do anything you want. • Form Responses• Force WordPress actions

• Reblogging• Dev Environment Clone/Deploy• Import from flatfile (products or phone numbers)• Fetching a new content

• You can use other languages to do things that WordPress isn’t good at• Datamining/Machine Learning• Image Cleanup• Specific Cached Data Flushing

Page 19: WordPress Rest API

WHERE CAN I LEARN MORE?• The website: http://wp-api.org (Don’t ignore v1. There’s good content there)• WordPress.TV

• Evan Volgas What it is, Why it matters and What you need to know about it.http://wordpress.tv/2016/07/26/evan-volgas-wp-rest-api-what-it-is-why-it-matters-what-you-need-to-know-about-it/

• Jack Lennox’s Building Themes with the Rest APIhttp://wordpress.tv/2015/12/04/jack-lenox-building-themes-wp-rest-api/

• Jeff Well’s Stretching WordPresshttp://wordpress.tv/2016/06/09/jeff-wells-stretching-wordpress-to-the-limits-using-the-wp-rest-api/

• Jack Lennox’s Single Page Application talkhttp://wordpress.tv/2016/07/19/jack-lenox-building-single-page-applications-with-the-rest-api/

• Scott Taylor’s WordCamp US talk http://wordpress.tv/2015/12/10/scott-taylor-rest-in-action-the-live-coverage-platform-at-the-new-york-times/

Page 20: WordPress Rest API

BRIAN LAYMANhttp://eHermitsinc.comhttp://thecodecave.comhttp://www.slideshare.net/brianlaymanhttp://twitter.com/brianlayman @eHermitsMy info->your phone, Txt “ehermit” to [email protected]