WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!

Evan Mullins
Evan MullinsWordPress Developer at Bluehost
WP API, what is it good for?
Absolutely Everything!
Slides available: https://circlecube.com/does-wordpress/
WordCamp Birmingham - 29 October 2016
Introductions
Evan Mullins
Lead Web Developer
Brown Bag Marketing
@circlecube
circlecube.com
WordPress user since 2006
Full-time web developer since 2007
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
API
An (API) is a set of
subroutine definitions, protocols, and tools for building software and applications. A
good API makes it easier to develop a program by providing all the building blocks,
which are then put together by the programmer.
An API is best thought of as a contract provided by one piece of software to another.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
And growing!
October 2016 hits 16,000 apis
REST
It describes how one system can communicate state with another. One example would
be the state of a product (its name, description etc) represented as JSON. The
generalised idea of state is termed a resource.
JSON
is a lightweight data-interchange format.
It is easy for humans to read and write. It is easy for machines to parse and generate. It
is a text format that is completely language independent but uses conventions that are
familiar to programmers. These properties make JSON an ideal data-interchange
language.
JSON is built on two structures:
● A collection of name/value pairs. (object).
● An ordered list of values. (array).
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WP REST API
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.
Want to get your site’s posts?
Simply send a GET request to
Update user with ID 4?
Send a POST request to
/wp-json/wp/v2/users/4
Get all posts with the search term “awesome”?
GET
/wp-json/wp/v2/posts?search=awesome
It’s that easy.
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.
What’s with the V2?
A little history
Ryan McCue started development on an API, and then proposed a WordPress JSON
REST API Project for GSOC in April 2013 (when WordPress was on version 3.5).
Version 2.0 of the plugin rebuilt the first with lessons learned. The infrastructure
merged into WordPress core in version 4.4 (December 2015).
A little history
Although, it was proposed for 4.5, the
merge was delayed in order to build it out
with more endpoints. The REST API is
slated for inclusion in 4.7 after
considerable discussion and planning.
Authentication and further integration
with core will be a focus of 4.8.
Until 4.7 when this is officially merged into
core (December-ish 2016), we’ll need to
install the REST API feature Plugin.
It about to be real!
Did you catch that?
The REST API merging into
WordPress core.
In 4.7!
That’s a big deal!
WP
REST
API
Plugin
(for now)
Resources
https://github.com/WP-API/WP-API
Resources
http://v2.wp-api.org/
Slack Channel
Get Started Today Post 4.7
1. Install the plugin
2. Play
a. yoursite.com/wp-json/wp/v2/
1. Install the plugin
2. Play
a. yoursite.com/wp-json/wp/v2/
Install
The
Plugin
Need to do this
until the API
endpoints are
merged into core.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Nutshell
So in a nutshell, rather than getting your content or data via a
webpage as part of a website with php, html, css and javascript,
you can use whatever you want and retrieve your data via the
API. You’ll get json data that is compact and fast to transfer and
then you can do endless things with it. Create an app, load it into
another website, analyze it as data… it’s a great step for
WordPress and a great step to continuing democratizing the web.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Tools
Postman -
HTTP or
API client
Also: REST Easy for Firefox or httpie for the command line
Back to WordPress
The plugin/API exposes your data in JSON format in the following content types:
Posts
Pages
Media
Custom Post Types
Post Meta
Revisions
Comments
Terms
Users
Routes / Endpoints
Endpoints are functions available through the API and are simply urls. This can be
things like retrieving the API index, updating a post, or deleting a comment. Endpoints
perform a specific function, taking some number of parameters and return data to the
client.
A route is the “name” you use to access endpoints, used in the URL. A route can have
multiple endpoints associated with it, and which is used depends on the HTTP verb.
Routes / Endpoints Example
With the URL
The “route” is (the route doesn’t include wp-json because wp-json
is the base path for the API itself.)
This route has 3 endpoints:
● triggers a get_item method, returning the post data to the client.
● triggers an update_item method, taking the data to update, and returning the
updated post data.
● triggers a delete_item method, returning the now-deleted post data to the
client.
get list of latest posts
retrieve a single post
GET - to read data
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Standard arguments as you’d expect and more
, , , , , , ,
, , etc
GET
PUT - to create or update data
create post
update existing post
DELETE - to trash
Authentication
Authentication
When and why would you need this?
Internal wp code (plugin/theme development) use cookies.
External code (using wp api as service) use oauth.
Authentication
If you are building a theme or a plugin and want to access
the API of the same site where the theme or plugin will be,
you’ll want to authenticate with a cookie.
Use a nonce (WordPress security token) to connect to a
local API if your theme or plugin wants to connect to the
API of the site it’s on via ajax.
Nonce?
A nonce is a "number used once" or one-time token generated by a web site to identify
future requests to that site.
WordPress nonces aren't numbers, but are a hash made up of numbers and letters.
Nor are they used only once, but have a limited "lifetime" after which they expire.
WordPress's security tokens are called "nonces" despite the above noted differences
from true nonces, because they serve much the same purpose.
Authentication
Write a nonce in a
with
and then pass that nonce
value in your header.
The nonce in action
Authentication
Write a nonce in a
with
and then pass that
nonce value in your
header.
OAuth example here please
Authentication
OAuth authentication is the main authentication handler used for external clients. It
requires installing the OAuth plugin on the site which then handles authorizations and
tokens.
For examples on how to use OAuth Authentication checkout the Demo PHP API
Client, the CLI client or the API console.
WP REST API
OAuth 1.0a
Plugin
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
1. Discovery
2. Input Credentials
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
3. Authorized and Connected
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Extend - Do More
Modifying Responses
Adding Endpoints
Custom Content Types
ACF to API
Get ACF custom
fields to display in
your post JSON
easily with this
plugin!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Examples with Under the Hood Code
1. Mobile App - Content via WP
2. WordPress Plugin - Sitemapper
3. External site - Content via WP
4. WordPress Plugin - using js client
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Mobile App - US Presidents
An app will test your knowledge and teach you the Presidents of the USA – powered
with WordPress via
the REST API.
US Presidential Mobile App
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Plugin - Sitemapper
An in-house plugin at Brown Bag
Marketing to quickly get up and
running with a new WordPress site in
our prototyping and wireframing
multisite.
Construct your sitemap and the plugin
will create a new site (in the multisite
network) and via the API create new
pages according to the supplied
sitemap.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
External Site - Digital Dashboard
Angular web app built at
Brown Bag Marketing to
display live stats about a
bunch of sites. Connects
to sites like pingdom,
analytics etc, . The sites
are stored in WordPress
as a CPT and loaded
dynamically and it has
featured content that’s
pulled from the WP API.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Plugin - Revision Browser
Browse WordPress revisions on the
front-end of your website!
The REST API includes a
JavaScript/Backbone client library, which
provides an interface for the WP REST
API by providing Backbone Models and
Collections for all endpoints exposed the
API Schema.
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Examples
Story Corps.me
https://10up.com/blog/2015/scaling-storycorps-wordpress-json-api/ &
https://poststatus.com/how-storycorps-uses-wordpress-to-enable-storytelling-everywhere/
Calypso
NYTimes
http://www.slideshare.net/ScottTaylor1/rest-in-action-the-live-coverage-platform-at-the-new-york-times
Nomadbase.io
Custom
Contact
Forms
Plugin
https://wptavern.com/custom-contact-forms-plugin-passes-1-million-downloads-on-wordpress-org
Event
Espresso
4
WP
Live
Search
ACF to
REST API
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
A WordPress REST API White Paper
by Human Made
Additional Reading
The ultimate guide to the WordPress REST API
By Josh Pollock (Torque)
Additional Reading
Questions, Comments, More (better) Examples, Discuss
?
More Additional Reading
● http://v2.wp-api.org/reference/posts/
● https://demo.wp-api.org/
● https://deliciousbrains.com/creating-mobile-app-wp-api-react-native/
● https://css-tricks.com/wp-rest-api-remote-control-wordpress/
● https://wpshout.com/guide-wordpress-rest-api-interview-josh-pollock/
● https://code.tutsplus.com/tutorials/introducing-the-wp-rest-api--cms-24533
● https://www.sitepoint.com/wp-api/
● https://webdevstudios.com/2016/01/05/an-overview-of-the-wordpress-json-api-version-2/
● https://www.wpkube.com/implementations-wp-rest-api/
Thank You
!
Slides available at https://circlecube.com/does-wordpress/
1 of 87

Recommended

WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything! by
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!Evan Mullins
1K views51 slides
Mobile Hybrid Development with WordPress by
Mobile Hybrid Development with WordPressMobile Hybrid Development with WordPress
Mobile Hybrid Development with WordPressDanilo Ercoli
2.2K views23 slides
Developing Plugins For WordPress by
Developing Plugins For WordPressDeveloping Plugins For WordPress
Developing Plugins For WordPressLester Chan
1.3K views18 slides
Improve WordPress performance with caching and deferred execution of code by
Improve WordPress performance with caching and deferred execution of codeImprove WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeDanilo Ercoli
2.9K views29 slides
WordPress Development Tools and Best Practices by
WordPress Development Tools and Best PracticesWordPress Development Tools and Best Practices
WordPress Development Tools and Best PracticesDanilo Ercoli
7.3K views32 slides
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car... by
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Andrea Cardinali
3.1K views82 slides

More Related Content

What's hot

Anthony Somerset - Site Speed = Success! by
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!WordCamp Cape Town
990 views19 slides
CONTENT MANAGEMENT SYSTEM by
CONTENT MANAGEMENT SYSTEMCONTENT MANAGEMENT SYSTEM
CONTENT MANAGEMENT SYSTEMANAND PRAKASH
200 views100 slides
Building a community of Open Source intranet users by
Building a community of Open Source intranet usersBuilding a community of Open Source intranet users
Building a community of Open Source intranet usersLuke Oatham
1.5K views46 slides
Why it's dangerous to turn off automatic updates and here's how to do it by
Why it's dangerous to turn off automatic updates and here's how to do itWhy it's dangerous to turn off automatic updates and here's how to do it
Why it's dangerous to turn off automatic updates and here's how to do itOnni Hakala
1.2K views27 slides
Choosing WordPress Plugins (WordCamp Raleigh 2016) by
Choosing WordPress Plugins (WordCamp Raleigh 2016)Choosing WordPress Plugins (WordCamp Raleigh 2016)
Choosing WordPress Plugins (WordCamp Raleigh 2016)andisites
1.7K views27 slides
Web Blogs by
Web BlogsWeb Blogs
Web Blogsdoba2007
1.3K views43 slides

What's hot(20)

CONTENT MANAGEMENT SYSTEM by ANAND PRAKASH
CONTENT MANAGEMENT SYSTEMCONTENT MANAGEMENT SYSTEM
CONTENT MANAGEMENT SYSTEM
ANAND PRAKASH200 views
Building a community of Open Source intranet users by Luke Oatham
Building a community of Open Source intranet usersBuilding a community of Open Source intranet users
Building a community of Open Source intranet users
Luke Oatham1.5K views
Why it's dangerous to turn off automatic updates and here's how to do it by Onni Hakala
Why it's dangerous to turn off automatic updates and here's how to do itWhy it's dangerous to turn off automatic updates and here's how to do it
Why it's dangerous to turn off automatic updates and here's how to do it
Onni Hakala1.2K views
Choosing WordPress Plugins (WordCamp Raleigh 2016) by andisites
Choosing WordPress Plugins (WordCamp Raleigh 2016)Choosing WordPress Plugins (WordCamp Raleigh 2016)
Choosing WordPress Plugins (WordCamp Raleigh 2016)
andisites1.7K views
Web Blogs by doba2007
Web BlogsWeb Blogs
Web Blogs
doba20071.3K views
Install WordPress Blogging Software with EasyPHP by Rupesh Kumar
Install WordPress Blogging Software with EasyPHPInstall WordPress Blogging Software with EasyPHP
Install WordPress Blogging Software with EasyPHP
Rupesh Kumar11.5K views
Introduction to word press by Lucky Ali
Introduction to word pressIntroduction to word press
Introduction to word press
Lucky Ali439 views
Ako na vlastne WP temy by Juraj Kiss
Ako na vlastne WP temyAko na vlastne WP temy
Ako na vlastne WP temy
Juraj Kiss822 views
WordPress Performance by dsero
WordPress PerformanceWordPress Performance
WordPress Performance
dsero1K views
Wordpress Plugin Development Short Tutorial by Christos Zigkolis
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
Christos Zigkolis11.4K views
Managing Multisite: Lessons from a Large Network by William Earnhardt
Managing Multisite: Lessons from a Large NetworkManaging Multisite: Lessons from a Large Network
Managing Multisite: Lessons from a Large Network
William Earnhardt2.3K views
Professional WordPress Development with Vagrant - Andrea Cardinali - WordCam... by Andrea Cardinali
Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCam...Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCam...
Professional WordPress Development with Vagrant - Andrea Cardinali - WordCam...
Andrea Cardinali1.4K views
Basic Wordpress PPT by mayur akabari
Basic Wordpress PPT Basic Wordpress PPT
Basic Wordpress PPT
mayur akabari48.4K views
State of play for Joomla - Nov 2014 by Tim Plummer
State of play for Joomla - Nov 2014State of play for Joomla - Nov 2014
State of play for Joomla - Nov 2014
Tim Plummer2.1K views
WordPress Performance optimization by Brecht Ryckaert
WordPress Performance optimizationWordPress Performance optimization
WordPress Performance optimization
Brecht Ryckaert1.2K views

Viewers also liked

Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV by
Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV
Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV GGDBologna
1.2K views20 slides
Just Press Publish by
Just Press PublishJust Press Publish
Just Press PublishAlycia Mitchell
1.5K views43 slides
Responsive Images (STL WordCamp 2014) by
Responsive Images (STL WordCamp 2014)Responsive Images (STL WordCamp 2014)
Responsive Images (STL WordCamp 2014)joemcgill
2.2K views36 slides
Customizing the custom loop wordcamp 2012-jeff by
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeffAlexander Sapountzis
2.1K views17 slides
Options, and Transients, and Theme Mods — Oh my! by
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Konstantin Obenland
2.7K views40 slides
Customize your theme using css by
Customize your theme using cssCustomize your theme using css
Customize your theme using cssMichael Arestad
2.1K views69 slides

Viewers also liked(20)

Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV by GGDBologna
Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV
Responsività e integrazioni social: l’utente al centro nel nuovo sito Volvo TV
GGDBologna1.2K views
Responsive Images (STL WordCamp 2014) by joemcgill
Responsive Images (STL WordCamp 2014)Responsive Images (STL WordCamp 2014)
Responsive Images (STL WordCamp 2014)
joemcgill2.2K views
Options, and Transients, and Theme Mods — Oh my! by Konstantin Obenland
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
Konstantin Obenland2.7K views
Customize your theme using css by Michael Arestad
Customize your theme using cssCustomize your theme using css
Customize your theme using css
Michael Arestad2.1K views
Wordpress Plugin Development Practices by serversideup
Wordpress Plugin Development PracticesWordpress Plugin Development Practices
Wordpress Plugin Development Practices
serversideup1.8K views
how to not design like a developer by tracy apps
how to not design like a developerhow to not design like a developer
how to not design like a developer
tracy apps1.3K views
Introducing the wpXtreme ecosystem by GGDBologna
Introducing the wpXtreme ecosystemIntroducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystem
GGDBologna1.5K views
Build your site tonight, be blogging tomorrow by Warren Denley
Build your site tonight, be blogging tomorrowBuild your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrow
Warren Denley1.7K views
Can You Go Commercial by garthkoyle
Can You Go CommercialCan You Go Commercial
Can You Go Commercial
garthkoyle1.5K views
WordPress & eCommerce - WCLV 2011 by Shayne Sanderson
WordPress & eCommerce - WCLV 2011WordPress & eCommerce - WCLV 2011
WordPress & eCommerce - WCLV 2011
Shayne Sanderson1.1K views
Working with WP_Query in WordPress by topher1kenobe
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
topher1kenobe1.7K views
Everything You Ever Wanted to Know About Keyword Research (And Probably a Few... by Kick Point
Everything You Ever Wanted to Know About Keyword Research (And Probably a Few...Everything You Ever Wanted to Know About Keyword Research (And Probably a Few...
Everything You Ever Wanted to Know About Keyword Research (And Probably a Few...
Kick Point 1.7K views
WordPress in a Time of Crisis by Michelle Amaral
WordPress in a Time of CrisisWordPress in a Time of Crisis
WordPress in a Time of Crisis
Michelle Amaral2.5K views
Questions you’re too afraid to ask by Eric Mann
Questions you’re too afraid to askQuestions you’re too afraid to ask
Questions you’re too afraid to ask
Eric Mann1.4K views
SEO para Wordpress (WordCamp Salvador) by Ian Castro
SEO para Wordpress (WordCamp Salvador)SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)
Ian Castro2.2K views
Wc norrkoping-2015 by pelmered
Wc norrkoping-2015Wc norrkoping-2015
Wc norrkoping-2015
pelmered1.4K views
Node.js to the rescue by Marko Heijnen
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
Marko Heijnen2.4K views

Similar to WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!

WordCamp Wilmington 2017 WP-API Why? by
WordCamp Wilmington 2017   WP-API Why?WordCamp Wilmington 2017   WP-API Why?
WordCamp Wilmington 2017 WP-API Why?Evan Mullins
1.9K views101 slides
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf by
WORDPRESS_REST_API_WORDPRESS_REST_API.pdfWORDPRESS_REST_API_WORDPRESS_REST_API.pdf
WORDPRESS_REST_API_WORDPRESS_REST_API.pdfAngy668409
3 views17 slides
Building native mobile apps with word press by
Building native mobile apps with word pressBuilding native mobile apps with word press
Building native mobile apps with word pressNikhil Vishnu P.V
5.2K views39 slides
Apitesting.pptx by
Apitesting.pptxApitesting.pptx
Apitesting.pptxNamanVerma88
21 views16 slides
Play with force.com metadata by
Play with force.com metadataPlay with force.com metadata
Play with force.com metadataRakesh Kumar Kedia
292 views13 slides
Api_testing.pdf by
Api_testing.pdfApi_testing.pdf
Api_testing.pdfRameshN849679
12 views146 slides

Similar to WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!(20)

WordCamp Wilmington 2017 WP-API Why? by Evan Mullins
WordCamp Wilmington 2017   WP-API Why?WordCamp Wilmington 2017   WP-API Why?
WordCamp Wilmington 2017 WP-API Why?
Evan Mullins1.9K views
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf by Angy668409
WORDPRESS_REST_API_WORDPRESS_REST_API.pdfWORDPRESS_REST_API_WORDPRESS_REST_API.pdf
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf
Angy6684093 views
Building native mobile apps with word press by Nikhil Vishnu P.V
Building native mobile apps with word pressBuilding native mobile apps with word press
Building native mobile apps with word press
Nikhil Vishnu P.V5.2K views
Build APIs With Kapow Mashup Server by Andreas Krohn
Build APIs With Kapow Mashup ServerBuild APIs With Kapow Mashup Server
Build APIs With Kapow Mashup Server
Andreas Krohn1.3K views
Case Study: Putting The Watson Developer Cloud to Work - by Doron Katz & Luci... by Carlos Tomas
Case Study: Putting The Watson Developer Cloud to Work - by Doron Katz & Luci...Case Study: Putting The Watson Developer Cloud to Work - by Doron Katz & Luci...
Case Study: Putting The Watson Developer Cloud to Work - by Doron Katz & Luci...
Carlos Tomas297 views
Talking to 25% of the web - In-depth report and analysis on the WordPress RES... by Stephane Beladaci
Talking to 25% of the web - In-depth report and analysis on the WordPress RES...Talking to 25% of the web - In-depth report and analysis on the WordPress RES...
Talking to 25% of the web - In-depth report and analysis on the WordPress RES...
Stephane Beladaci1.2K views
Web API or WCF - An Architectural Comparison by Adnan Masood
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
Adnan Masood56.8K views
How to develop an API with PHP, JSON, and POSTMAN in 9 Steps.pdf by Be Problem Solver
How to develop an API with PHP, JSON, and POSTMAN in 9 Steps.pdfHow to develop an API with PHP, JSON, and POSTMAN in 9 Steps.pdf
How to develop an API with PHP, JSON, and POSTMAN in 9 Steps.pdf
Be Problem Solver108 views
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017 by Evan Mullins
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017 So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Evan Mullins424 views
Using WordPress as a web application platform by Joe Querin
Using WordPress as a web application platformUsing WordPress as a web application platform
Using WordPress as a web application platform
Joe Querin442 views

More from Evan Mullins

WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word... by
WordCamp Atlanta -  April 15 2018 - dev team workflow and processes with word...WordCamp Atlanta -  April 15 2018 - dev team workflow and processes with word...
WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word...Evan Mullins
1.7K views49 slides
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development by
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentEvan Mullins
356 views124 slides
Meetup: The big change coming to WordPress in 2018 - Gutenberg by
Meetup: The big change coming to WordPress in 2018 - GutenbergMeetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - GutenbergEvan Mullins
176 views106 slides
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team! by
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!Evan Mullins
1.3K views111 slides
Modifying your themes design - Learning CSS - Atlanta WordPress users group by
Modifying your themes design - Learning CSS - Atlanta WordPress users groupModifying your themes design - Learning CSS - Atlanta WordPress users group
Modifying your themes design - Learning CSS - Atlanta WordPress users groupEvan Mullins
2.7K views42 slides
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M... by
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...Evan Mullins
4.5K views59 slides

More from Evan Mullins(8)

WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word... by Evan Mullins
WordCamp Atlanta -  April 15 2018 - dev team workflow and processes with word...WordCamp Atlanta -  April 15 2018 - dev team workflow and processes with word...
WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word...
Evan Mullins1.7K views
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development by Evan Mullins
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins356 views
Meetup: The big change coming to WordPress in 2018 - Gutenberg by Evan Mullins
Meetup: The big change coming to WordPress in 2018 - GutenbergMeetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - Gutenberg
Evan Mullins176 views
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team! by Evan Mullins
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins1.3K views
Modifying your themes design - Learning CSS - Atlanta WordPress users group by Evan Mullins
Modifying your themes design - Learning CSS - Atlanta WordPress users groupModifying your themes design - Learning CSS - Atlanta WordPress users group
Modifying your themes design - Learning CSS - Atlanta WordPress users group
Evan Mullins2.7K views
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M... by Evan Mullins
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Custom post types- Choose Your Own Adventure - WordCamp Atlanta 2014 - Evan M...
Evan Mullins4.5K views
Firstborn child theme word camp presentation - atlanta 2013 by Evan Mullins
Firstborn child theme   word camp presentation - atlanta 2013Firstborn child theme   word camp presentation - atlanta 2013
Firstborn child theme word camp presentation - atlanta 2013
Evan Mullins4.7K views
From PSD to WP Theme by Evan Mullins
From PSD to WP ThemeFrom PSD to WP Theme
From PSD to WP Theme
Evan Mullins1.3K views

Recently uploaded

SUPPLIER SOURCING.pptx by
SUPPLIER SOURCING.pptxSUPPLIER SOURCING.pptx
SUPPLIER SOURCING.pptxangelicacueva6
15 views1 slide
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
19 views29 slides
Democratising digital commerce in India-Report by
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
15 views161 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 views25 slides
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
85 views32 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
263 views86 slides

Recently uploaded(20)

STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson85 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta26 views

WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!

  • 1. WP API, what is it good for? Absolutely Everything! Slides available: https://circlecube.com/does-wordpress/ WordCamp Birmingham - 29 October 2016
  • 2. Introductions Evan Mullins Lead Web Developer Brown Bag Marketing @circlecube circlecube.com WordPress user since 2006 Full-time web developer since 2007
  • 5. API An (API) is a set of subroutine definitions, protocols, and tools for building software and applications. A good API makes it easier to develop a program by providing all the building blocks, which are then put together by the programmer. An API is best thought of as a contract provided by one piece of software to another.
  • 7. And growing! October 2016 hits 16,000 apis
  • 8. REST It describes how one system can communicate state with another. One example would be the state of a product (its name, description etc) represented as JSON. The generalised idea of state is termed a resource.
  • 9. JSON is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is a text format that is completely language independent but uses conventions that are familiar to programmers. These properties make JSON an ideal data-interchange language. JSON is built on two structures: ● A collection of name/value pairs. (object). ● An ordered list of values. (array).
  • 12. 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.
  • 13. 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.
  • 14. Want to get your site’s posts? Simply send a GET request to
  • 15. Update user with ID 4? Send a POST request to /wp-json/wp/v2/users/4
  • 16. Get all posts with the search term “awesome”? GET /wp-json/wp/v2/posts?search=awesome It’s that easy.
  • 17. 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.
  • 19. A little history Ryan McCue started development on an API, and then proposed a WordPress JSON REST API Project for GSOC in April 2013 (when WordPress was on version 3.5). Version 2.0 of the plugin rebuilt the first with lessons learned. The infrastructure merged into WordPress core in version 4.4 (December 2015).
  • 20. A little history Although, it was proposed for 4.5, the merge was delayed in order to build it out with more endpoints. The REST API is slated for inclusion in 4.7 after considerable discussion and planning. Authentication and further integration with core will be a focus of 4.8. Until 4.7 when this is officially merged into core (December-ish 2016), we’ll need to install the REST API feature Plugin.
  • 21. It about to be real! Did you catch that? The REST API merging into WordPress core. In 4.7! That’s a big deal!
  • 26. Get Started Today Post 4.7 1. Install the plugin 2. Play a. yoursite.com/wp-json/wp/v2/ 1. Install the plugin 2. Play a. yoursite.com/wp-json/wp/v2/
  • 27. Install The Plugin Need to do this until the API endpoints are merged into core.
  • 29. Nutshell So in a nutshell, rather than getting your content or data via a webpage as part of a website with php, html, css and javascript, you can use whatever you want and retrieve your data via the API. You’ll get json data that is compact and fast to transfer and then you can do endless things with it. Create an app, load it into another website, analyze it as data… it’s a great step for WordPress and a great step to continuing democratizing the web.
  • 31. Tools Postman - HTTP or API client Also: REST Easy for Firefox or httpie for the command line
  • 32. Back to WordPress The plugin/API exposes your data in JSON format in the following content types: Posts Pages Media Custom Post Types Post Meta Revisions Comments Terms Users
  • 33. Routes / Endpoints Endpoints are functions available through the API and are simply urls. This can be things like retrieving the API index, updating a post, or deleting a comment. Endpoints perform a specific function, taking some number of parameters and return data to the client. A route is the “name” you use to access endpoints, used in the URL. A route can have multiple endpoints associated with it, and which is used depends on the HTTP verb.
  • 34. Routes / Endpoints Example With the URL The “route” is (the route doesn’t include wp-json because wp-json is the base path for the API itself.) This route has 3 endpoints: ● triggers a get_item method, returning the post data to the client. ● triggers an update_item method, taking the data to update, and returning the updated post data. ● triggers a delete_item method, returning the now-deleted post data to the client.
  • 35. get list of latest posts retrieve a single post GET - to read data
  • 37. Standard arguments as you’d expect and more , , , , , , , , , etc GET
  • 38. PUT - to create or update data create post update existing post
  • 39. DELETE - to trash
  • 41. Authentication When and why would you need this? Internal wp code (plugin/theme development) use cookies. External code (using wp api as service) use oauth.
  • 42. Authentication If you are building a theme or a plugin and want to access the API of the same site where the theme or plugin will be, you’ll want to authenticate with a cookie. Use a nonce (WordPress security token) to connect to a local API if your theme or plugin wants to connect to the API of the site it’s on via ajax.
  • 43. Nonce? A nonce is a "number used once" or one-time token generated by a web site to identify future requests to that site. WordPress nonces aren't numbers, but are a hash made up of numbers and letters. Nor are they used only once, but have a limited "lifetime" after which they expire. WordPress's security tokens are called "nonces" despite the above noted differences from true nonces, because they serve much the same purpose.
  • 44. Authentication Write a nonce in a with and then pass that nonce value in your header.
  • 45. The nonce in action
  • 46. Authentication Write a nonce in a with and then pass that nonce value in your header.
  • 48. Authentication OAuth authentication is the main authentication handler used for external clients. It requires installing the OAuth plugin on the site which then handles authorizations and tokens. For examples on how to use OAuth Authentication checkout the Demo PHP API Client, the CLI client or the API console.
  • 49. WP REST API OAuth 1.0a Plugin
  • 54. 3. Authorized and Connected
  • 56. Extend - Do More Modifying Responses Adding Endpoints Custom Content Types
  • 57. ACF to API Get ACF custom fields to display in your post JSON easily with this plugin!
  • 60. Examples with Under the Hood Code 1. Mobile App - Content via WP 2. WordPress Plugin - Sitemapper 3. External site - Content via WP 4. WordPress Plugin - using js client
  • 62. Mobile App - US Presidents An app will test your knowledge and teach you the Presidents of the USA – powered with WordPress via the REST API.
  • 66. Plugin - Sitemapper An in-house plugin at Brown Bag Marketing to quickly get up and running with a new WordPress site in our prototyping and wireframing multisite. Construct your sitemap and the plugin will create a new site (in the multisite network) and via the API create new pages according to the supplied sitemap.
  • 68. External Site - Digital Dashboard Angular web app built at Brown Bag Marketing to display live stats about a bunch of sites. Connects to sites like pingdom, analytics etc, . The sites are stored in WordPress as a CPT and loaded dynamically and it has featured content that’s pulled from the WP API.
  • 71. Plugin - Revision Browser Browse WordPress revisions on the front-end of your website! The REST API includes a JavaScript/Backbone client library, which provides an interface for the WP REST API by providing Backbone Models and Collections for all endpoints exposed the API Schema.
  • 83. A WordPress REST API White Paper by Human Made Additional Reading
  • 84. The ultimate guide to the WordPress REST API By Josh Pollock (Torque) Additional Reading
  • 85. Questions, Comments, More (better) Examples, Discuss ?
  • 86. More Additional Reading ● http://v2.wp-api.org/reference/posts/ ● https://demo.wp-api.org/ ● https://deliciousbrains.com/creating-mobile-app-wp-api-react-native/ ● https://css-tricks.com/wp-rest-api-remote-control-wordpress/ ● https://wpshout.com/guide-wordpress-rest-api-interview-josh-pollock/ ● https://code.tutsplus.com/tutorials/introducing-the-wp-rest-api--cms-24533 ● https://www.sitepoint.com/wp-api/ ● https://webdevstudios.com/2016/01/05/an-overview-of-the-wordpress-json-api-version-2/ ● https://www.wpkube.com/implementations-wp-rest-api/
  • 87. Thank You ! Slides available at https://circlecube.com/does-wordpress/