A Quick Trip Down the Rabbit Hole - An Introduction into what the WP-REST-API is and what you can do with it. This is meant as an explanation for a site owner/project lead who wants to learn what this new technology means and for the developer who wants to understand where this will take the WordPress community over the next decade and beyond.
2. • 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
5. 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
6. 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
7. 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/
8. 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
9. 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
10. 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
11. 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
13. WHAT CAN YOU DO
WITH THE WP-REST-API?
https://backpress.org/
• Anybody remember
BackPress?
• 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
14. 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
15. 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
16. 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
17. 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 WordPress
Will be used to show your as your Tesla
comes through the production line.
18. 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
19. 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 API
http://wordpress.tv/2015/12/04/jack-lenox-building-themes-wp-rest-api/
• Jeff Well’s Stretching WordPress
http://wordpress.tv/2016/06/09/jeff-wells-stretching-wordpress-to-the-limits-using-the-wp-rest-api/
• Jack Lennox’s Single Page Application talk
http://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/