JSON REST API for WordPress

Taylor Lovett
Taylor LovettDirector of Web Engineering at 10up
JSON REST API for WordPress 
@tlovett12 
+ JSON 
REST API 
=
Who Am I? 
• My name is Taylor Lovett! 
• Director of Web Engineering at 10up 
• Open source community member 
• WordPress core contributor 
• WP API team member 
@tlovett12
We are hiring! 
@tlovett12
So what’s this new WP API thing all 
about? Don’t we already have one?
Right now, we have XML-RPC. It works but 
is extremely hard to use and outdated.
Comparison to other WordPress API’s 
! 
https://github.com/WP-API/WP-API/blob/ 
master/docs/comparison.md
Why JSON REST API? 
• In a nutshell, JSON REST API’s have swept the 
web becoming an almost standard. They are 
extremely intuitive and provide an easy way to 
distribute, collect, and modify data. 
Let’s break it down a bit.
JSON 
• JSON is an abbreviation for “JavaScript Object Notation” 
• It’s simply a way to describe data that is lightweight and 
extremely easy to use. Arguably much easier to use than 
XML.
REST 
• REST (Representational State Transfer) is an architectural style 
that dictates how HTTP and URI’s should be used and organized. 
• Verbs and resources: GET /post/1 
• Hypermedia as the Engine of Application State (HATEOAS) - 
Server provides everything you need to know how to use it in a 
response. 
• Actions are autonomous and do not depend on each other. 
• Bottom line: RESTful API’s have become extremely popular 
across the web. They are much easier to use than things like RPC 
or SOAP.
And of course, API 
• An API (Application Programming Interface) is a 
set of entry points that allow you to interact with 
a platform (WordPress in this case).
Ryan McCue and Contributors
How can I start using it now?
First, install the plugin 
http://wordpress.org/plugins/json-rest-api/ 
! 
Core integration coming soon.
What does the API allow me to do? 
/wp-json/ 
Shows all the routes and endpoints available 
/wp-json/posts 
Create, read, update, and delete posts 
/wp-json/users 
Create, read, update, and delete users 
/wp-json/media 
Create, read, update, and delete media items 
/wp-json/taxonomies 
Read taxonomies and terms 
/wp-json/pages/ 
Create, read, update, and delete pages
The API is rich with functionality. 
Explore the documentation! 
http://wp-api.org/docs-development/ 
Let’s look at a few key endpoints.
List Posts 
[{! 
"ID": 11297,! 
"title": "Post 19",! 
"status": "publish",! 
"type": "post",! 
"author": 1,! 
"content": "",! 
"parent": null,! 
"link": "http://example.com/2014/08/post-19/",! 
"format": "standard",! 
"slug": "post-19",! 
"guid": "http://example.com/2014/08/post-19/",! 
"excerpt": null,! 
"menu_order": 0,! 
"comment_status": "closed",! 
"ping_status": "open",! 
"sticky": false,! 
"meta": {},! 
"featured_image": null,! 
"terms": {}! 
}] 
GET /wp-json/posts
List Posts 
Endpoint: /wp-json/posts 
Takes a number of useful parameters: 
• Filter[]: Accepts WP_Query arguments 
• Page: Allows for pagination 
• Context: Determines usage context i.e. “view or edit” 
• … 
https://github.com/WP-API/WP-API/blob/master/docs/routes/routes.md
Retrieve A Post 
{! 
"ID": 11297,! 
"title": "Post 19",! 
"status": "publish",! 
"type": "post",! 
"author": 1,! 
"content": "",! 
"parent": null,! 
"link": "http://example.com/2014/08/post-19/",! 
"format": "standard",! 
"slug": "post-19",! 
"guid": "http://example.com/2014/08/post-19/",! 
"excerpt": null,! 
"menu_order": 0,! 
"comment_status": "closed",! 
"ping_status": "open",! 
"sticky": false,! 
"meta": {},! 
"featured_image": null,! 
"terms": {}! 
} 
GET /wp-json/posts/<id>
Edit A Post 
PUT /wp-json/posts/<id> 
curl -X PUT -H “Content-Type: application/json” -d ‘! 
{! 
"title": “Updated Title",! 
“content_raw": “Updated post content"! 
}! 
‘ -u admin:password http://example.com/wp-json/posts/<id> 
We need to send a PUT request to this endpoint with 
our post data. Of course we must authenticate before 
doing this.
Three ways to authenticate 
• Cookie Authentication (client side) 
• HTTP Basic Authentication 
• OAuth 1
HTTP Basic Authentication 
First install the WP Basic Auth Plugin: 
https://github.com/WP-API/Basic-Auth 
Remember this piece of our cURL request? 
-u admin:password 
That’s HTTP Basic Authentication! Essentially we are authenticating 
by passing an HTTP header like this: 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Where that crazy looking string is username:password base64 
encoded.
HTTP Basic Authentication 
should only be used for testing!
OAuth 1.0a 
First install the WP OAuth Plugin: 
https://github.com/WP-API/OAuth1 
OAuth is outside of the scope of this talk. However, it 
should be used instead of HTTP Basic Auth when 
building external applications that interact with the 
API. Rather than giving someone an account on your 
site, you can give them temporary access with 
OAuth.
Create A Post 
POST /wp-json/posts/ 
curl -X POST -H “Content-Type: application/json” -d ‘! 
{! 
"title": “Title",! 
“content_raw": “Post content"! 
}! 
‘ -u admin:password http://example.com/wp-json/posts/ 
Notice we are using a POST request this time.
Taxonomies 
GET /wp-json/taxonomies 
[! 
{! 
"name": "Categories",! 
"slug": "category",! 
"labels": {},! 
"types": { /* Registered post types */ },! 
"show_cloud": true,! 
"hierarchical": true,! 
"meta": {}! 
},! 
{! 
"name": "Tags",! 
"slug": "post_tag",! 
"labels": {},! 
"types": { /* Registered post types */ },! 
"show_cloud": true,! 
"hierarchical": false,! 
"meta": {}! 
}! 
}! 
]
Taxonomy 
GET /wp-json/taxonomies/<taxonomy> 
{! 
"name": "Categories",! 
"slug": "category",! 
"labels": {},! 
"types": { /* Registered post types */ },! 
"show_cloud": true,! 
"hierarchical": true,! 
"meta": {}! 
}
Taxonomy Terms 
GET /wp-json/taxonomies/<taxonomy>/terms 
[! 
{! 
"ID": 1,! 
"name": "Books",! 
"slug": "books",! 
"description": "",! 
"parent": null,! 
"count": 1,! 
"link": "http://example.com/category/books/",! 
"meta": {}! 
},! 
{! 
"ID": 2,! 
"name": "Products",! 
"slug": "products",! 
"description": "",! 
"parent": null,! 
"count": 1,! 
"link": "http://example.com/category/products/",! 
"meta": {}! 
}! 
]
Build Your Own Routes and Endpoints 
WP API is very extensible (custom post types!) 
http://wp-api.org/guides/extending.html
What can I do with the JSON 
REST API for WordPress?
JavaScript 
Interact with your (or someone else’s) WordPress install with 
JavaScript. 
Backbone.js Client: 
https://github.com/WP-API/client-js 
! 
! 
Node.js Client: 
https://github.com/kadamwhite/wordpress-rest-api 
!
Backbone.js 
• Backbone.js is a JavaScript framework that lets 
you structure code in terms of models, views, 
and collections. It works great with RESTful 
JSON API’s.
_s_backbone 
• _s or underscores is a popular starter theme by 
Automattic: 
https://github.com/automattic/_s 
• _s_backbone is an _s fork that powers post 
loops using the WP API Backbone client
https://github.com/tlovett1/_s_backbone
What does this mean? 
• It means _s_backbone is a starter theme with 
infinite scroll built-in using the WP API Backbone 
client. 
• Infinite scroll is the concept of loading multiple 
rounds of entities without reloading the page. 
Let’s look at some code!
This is some JavaScript you could add to a theme or 
plugin to display your site’s posts. You will first need 
to have JSON REST API for WordPress installed and 
the “wp-api” JavaScript dependency enqueued. 
functions.php: 
js/scripts.js:
If you learned nothing so far, 
know this: 
You can do amazing things with the JSON REST 
API for WordPress. 
With core integration and ~23% of the web using 
this API in the near future, you will have much 
easier access to data across the web.
Questions? 
@tlovett12! 
taylor.lovett@10up.com! 
taylorlovett.com 
We need to send a PUT request to this endpoint with 
our post data. Of course we must authenticate before 
doing this.
1 of 37

Recommended

The JSON REST API for WordPress by
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
30.9K views37 slides
Beyond The Browser - Creating a RESTful Web Service With WordPress by
Beyond The Browser - Creating a RESTful Web Service With WordPressBeyond The Browser - Creating a RESTful Web Service With WordPress
Beyond The Browser - Creating a RESTful Web Service With WordPressChristopher Reding
6.3K views15 slides
Best Practices for WordPress in Enterprise by
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
10.8K views59 slides
Best Practices for Building WordPress Applications by
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
6.1K views50 slides
You Got React.js in My PHP by
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHPTaylor Lovett
7.2K views31 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

More Related Content

What's hot

Best Practices for WordPress by
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
11.3K views51 slides
Develop webservice in PHP by
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHPSanil Subhash Chandra Bose
7.8K views25 slides
Scalable web application architecture by
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
32.5K views44 slides
Advanced WordPress Development Environments by
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development EnvironmentsBeau Lebens
2.4K views103 slides
Building Your First App with MongoDB by
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
16.9K views69 slides
Put a little Backbone in your WordPress by
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPressadamsilverstein
2.5K views32 slides

What's hot(20)

Best Practices for WordPress by Taylor Lovett
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
Taylor Lovett11.3K views
Scalable web application architecture by postrational
Scalable web application architectureScalable web application architecture
Scalable web application architecture
postrational32.5K views
Advanced WordPress Development Environments by Beau Lebens
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
Beau Lebens2.4K views
Building Your First App with MongoDB by MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
MongoDB16.9K views
Put a little Backbone in your WordPress by adamsilverstein
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
adamsilverstein2.5K views
CouchDB for Web Applications - Erlang Factory London 2009 by Jason Davies
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
Jason Davies2.2K views
The never-ending REST API design debate by Restlet
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debate
Restlet10.1K views
Introduction to Plugin Programming, WordCamp Miami 2011 by David Carr
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr1.5K views
Differential Sync and JSON Patch @ SpringOne2GX 2014 by Brian Cavalier
Differential Sync and JSON Patch @ SpringOne2GX 2014Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014
Brian Cavalier9.6K views
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails by Toru Kawamura
Hypermedia: The Missing Element to Building Adaptable Web APIs in RailsHypermedia: The Missing Element to Building Adaptable Web APIs in Rails
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails
Toru Kawamura26.1K views
Introducing RaveJS: Spring Boot concepts for JavaScript applications by John Hann
Introducing RaveJS: Spring Boot concepts for JavaScript applicationsIntroducing RaveJS: Spring Boot concepts for JavaScript applications
Introducing RaveJS: Spring Boot concepts for JavaScript applications
John Hann3.1K views
REST API Best Practices & Implementing in Codeigniter by Sachin G Kulkarni
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni39.4K views
Transforming WordPress Search and Query Performance with Elasticsearch by Taylor Lovett
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
Taylor Lovett8K views
REST Web API with MongoDB by MongoDB
REST Web API with MongoDBREST Web API with MongoDB
REST Web API with MongoDB
MongoDB7K views
Introduction to CouchDB by OpusVL
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
OpusVL1.4K views
Understanding and testing restful web services by mwinteringham
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
mwinteringham2.2K views
Djangocon 2014 angular + django by Nina Zakharenko
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
Nina Zakharenko8.3K views
Software Development with Open Source by OpusVL
Software Development with Open SourceSoftware Development with Open Source
Software Development with Open Source
OpusVL773 views
REST Easy with AngularJS - ng-grid CRUD EXAMPLE by reneechemel
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
reneechemel10.7K views

Viewers also liked

WordPress & A Mobile App by
WordPress & A Mobile AppWordPress & A Mobile App
WordPress & A Mobile AppAmit K Sharma
1.2K views26 slides
マルチパブリッシング プラットフォームとしてのWordPress by
マルチパブリッシング プラットフォームとしてのWordPressマルチパブリッシング プラットフォームとしてのWordPress
マルチパブリッシング プラットフォームとしてのWordPress文樹 高橋
17.9K views42 slides
Demystifying the REST API by
Demystifying the REST APIDemystifying the REST API
Demystifying the REST APISamantha Quiñones
1.4K views93 slides
WordPress and the Enterprise by
WordPress and the EnterpriseWordPress and the Enterprise
WordPress and the EnterprisePrasad Ajinkya
819 views20 slides
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev... by
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...Eric Greene
7.2K views10 slides
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드... by
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...Shinichi Nishikawa
2.5K views21 slides

Viewers also liked(20)

WordPress & A Mobile App by Amit K Sharma
WordPress & A Mobile AppWordPress & A Mobile App
WordPress & A Mobile App
Amit K Sharma1.2K views
マルチパブリッシング プラットフォームとしてのWordPress by 文樹 高橋
マルチパブリッシング プラットフォームとしてのWordPressマルチパブリッシング プラットフォームとしてのWordPress
マルチパブリッシング プラットフォームとしてのWordPress
文樹 高橋17.9K views
WordPress and the Enterprise by Prasad Ajinkya
WordPress and the EnterpriseWordPress and the Enterprise
WordPress and the Enterprise
Prasad Ajinkya819 views
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev... by Eric Greene
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
Eric Greene7.2K views
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드... by Shinichi Nishikawa
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...
Shinichi Nishikawa2.5K views
PHP classの教室 by Yusuke Ando
PHP classの教室PHP classの教室
PHP classの教室
Yusuke Ando20.3K views
第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会 by Shinichi Nishikawa
第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会
第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会
Shinichi Nishikawa4.3K views
CodaでClipを使ってWordPress開発を早くするススメ。 by Shinichi Nishikawa
 CodaでClipを使ってWordPress開発を早くするススメ。 CodaでClipを使ってWordPress開発を早くするススメ。
CodaでClipを使ってWordPress開発を早くするススメ。
Shinichi Nishikawa4.6K views
WordPress中級者への道!テンプレートタグはどう動くのか!? by Shinichi Nishikawa
WordPress中級者への道!テンプレートタグはどう動くのか!?WordPress中級者への道!テンプレートタグはどう動くのか!?
WordPress中級者への道!テンプレートタグはどう動くのか!?
Shinichi Nishikawa5.3K views
8時間耐久CakePHP2 勉強会 by Yusuke Ando
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会
Yusuke Ando16.5K views
How to get your theme on Top 15 Popular Themes at WordPress.org by Catch Themes
How to get your theme on Top 15 Popular Themes at WordPress.orgHow to get your theme on Top 15 Popular Themes at WordPress.org
How to get your theme on Top 15 Popular Themes at WordPress.org
Catch Themes21.9K views
Getting Started With WP REST API by Kishor Kumar
Getting Started With WP REST APIGetting Started With WP REST API
Getting Started With WP REST API
Kishor Kumar1.3K views
Design Beautiful REST + JSON APIs by Stormpath
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
Stormpath225.9K views

Similar to JSON REST API for WordPress

JSON REST API for WordPress by
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
23K views24 slides
AtlasCamp2014: Introducing the Confluence REST API by
AtlasCamp2014: Introducing the Confluence REST APIAtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST APIAtlassian
7K views40 slides
Designing a beautiful REST json api by
Designing a beautiful REST json apiDesigning a beautiful REST json api
Designing a beautiful REST json api0x07de
196 views110 slides
WordPress APIs by
WordPress APIsWordPress APIs
WordPress APIsmdawaffe
13.2K views48 slides
Finding Restfulness - Madrid.rb April 2014 by
Finding Restfulness - Madrid.rb April 2014Finding Restfulness - Madrid.rb April 2014
Finding Restfulness - Madrid.rb April 2014samlown
475 views100 slides
Building Better Web APIs with Rails by
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
1.4K views58 slides

Similar to JSON REST API for WordPress(20)

JSON REST API for WordPress by Taylor Lovett
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
Taylor Lovett23K views
AtlasCamp2014: Introducing the Confluence REST API by Atlassian
AtlasCamp2014: Introducing the Confluence REST APIAtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST API
Atlassian7K views
Designing a beautiful REST json api by 0x07de
Designing a beautiful REST json apiDesigning a beautiful REST json api
Designing a beautiful REST json api
0x07de196 views
WordPress APIs by mdawaffe
WordPress APIsWordPress APIs
WordPress APIs
mdawaffe13.2K views
Finding Restfulness - Madrid.rb April 2014 by samlown
Finding Restfulness - Madrid.rb April 2014Finding Restfulness - Madrid.rb April 2014
Finding Restfulness - Madrid.rb April 2014
samlown475 views
Building Better Web APIs with Rails by All Things Open
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
All Things Open1.4K views
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs by Jorge Ferrer
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIsThe liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
Jorge Ferrer963 views
2.28.17 Introducing DSpace 7 Webinar Slides by DuraSpace
2.28.17 Introducing DSpace 7 Webinar Slides2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides
DuraSpace1.5K views
Have You Seen Spring Lately? by Joshua Long
Have You Seen Spring Lately?Have You Seen Spring Lately?
Have You Seen Spring Lately?
Joshua Long5.6K views
FOXX - a Javascript application framework on top of ArangoDB by ArangoDB Database
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database35.8K views
Survival Strategies for API Documentation: Presentation to Southwestern Ontar... by Tom Johnson
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Tom Johnson2.3K views
Using the new WordPress REST API by Caldera Labs
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs3.4K views
Rest in practice by Ian Brennan
Rest in practiceRest in practice
Rest in practice
Ian Brennan1.9K views
Be a microservices hero by OpenRestyCon
Be a microservices heroBe a microservices hero
Be a microservices hero
OpenRestyCon399 views
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
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data... by Big Data Spain
 Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data... Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
Big Data Spain1.3K views

More from Taylor Lovett

WordPress Acceptance Testing, Solved! by
WordPress Acceptance Testing, Solved!WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!Taylor Lovett
1.7K views27 slides
Best practices-wordpress-enterprise by
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterpriseTaylor Lovett
680 views59 slides
Wordpress search-elasticsearch by
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearchTaylor Lovett
23.3K views48 slides
Modernizing WordPress Search with Elasticsearch by
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
51.2K views48 slides
What You Missed in Computer Science by
What You Missed in Computer ScienceWhat You Missed in Computer Science
What You Missed in Computer ScienceTaylor Lovett
6.5K views36 slides
Saving Time with WP-CLI by
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLITaylor Lovett
13.6K views34 slides

More from Taylor Lovett(6)

WordPress Acceptance Testing, Solved! by Taylor Lovett
WordPress Acceptance Testing, Solved!WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!
Taylor Lovett1.7K views
Best practices-wordpress-enterprise by Taylor Lovett
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
Taylor Lovett680 views
Wordpress search-elasticsearch by Taylor Lovett
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearch
Taylor Lovett23.3K views
Modernizing WordPress Search with Elasticsearch by Taylor Lovett
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
Taylor Lovett51.2K views
What You Missed in Computer Science by Taylor Lovett
What You Missed in Computer ScienceWhat You Missed in Computer Science
What You Missed in Computer Science
Taylor Lovett6.5K views
Saving Time with WP-CLI by Taylor Lovett
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLI
Taylor Lovett13.6K views

Recently uploaded

"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
17 views34 slides
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
12 views36 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
18 views6 slides
PRODUCT PRESENTATION.pptx by
PRODUCT PRESENTATION.pptxPRODUCT PRESENTATION.pptx
PRODUCT PRESENTATION.pptxangelicacueva6
15 views1 slide
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
300 views20 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
58 views8 slides

Recently uploaded(20)

"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays17 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
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
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 Software280 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf

JSON REST API for WordPress

  • 1. JSON REST API for WordPress @tlovett12 + JSON REST API =
  • 2. Who Am I? • My name is Taylor Lovett! • Director of Web Engineering at 10up • Open source community member • WordPress core contributor • WP API team member @tlovett12
  • 3. We are hiring! @tlovett12
  • 4. So what’s this new WP API thing all about? Don’t we already have one?
  • 5. Right now, we have XML-RPC. It works but is extremely hard to use and outdated.
  • 6. Comparison to other WordPress API’s ! https://github.com/WP-API/WP-API/blob/ master/docs/comparison.md
  • 7. Why JSON REST API? • In a nutshell, JSON REST API’s have swept the web becoming an almost standard. They are extremely intuitive and provide an easy way to distribute, collect, and modify data. Let’s break it down a bit.
  • 8. JSON • JSON is an abbreviation for “JavaScript Object Notation” • It’s simply a way to describe data that is lightweight and extremely easy to use. Arguably much easier to use than XML.
  • 9. REST • REST (Representational State Transfer) is an architectural style that dictates how HTTP and URI’s should be used and organized. • Verbs and resources: GET /post/1 • Hypermedia as the Engine of Application State (HATEOAS) - Server provides everything you need to know how to use it in a response. • Actions are autonomous and do not depend on each other. • Bottom line: RESTful API’s have become extremely popular across the web. They are much easier to use than things like RPC or SOAP.
  • 10. And of course, API • An API (Application Programming Interface) is a set of entry points that allow you to interact with a platform (WordPress in this case).
  • 11. Ryan McCue and Contributors
  • 12. How can I start using it now?
  • 13. First, install the plugin http://wordpress.org/plugins/json-rest-api/ ! Core integration coming soon.
  • 14. What does the API allow me to do? /wp-json/ Shows all the routes and endpoints available /wp-json/posts Create, read, update, and delete posts /wp-json/users Create, read, update, and delete users /wp-json/media Create, read, update, and delete media items /wp-json/taxonomies Read taxonomies and terms /wp-json/pages/ Create, read, update, and delete pages
  • 15. The API is rich with functionality. Explore the documentation! http://wp-api.org/docs-development/ Let’s look at a few key endpoints.
  • 16. List Posts [{! "ID": 11297,! "title": "Post 19",! "status": "publish",! "type": "post",! "author": 1,! "content": "",! "parent": null,! "link": "http://example.com/2014/08/post-19/",! "format": "standard",! "slug": "post-19",! "guid": "http://example.com/2014/08/post-19/",! "excerpt": null,! "menu_order": 0,! "comment_status": "closed",! "ping_status": "open",! "sticky": false,! "meta": {},! "featured_image": null,! "terms": {}! }] GET /wp-json/posts
  • 17. List Posts Endpoint: /wp-json/posts Takes a number of useful parameters: • Filter[]: Accepts WP_Query arguments • Page: Allows for pagination • Context: Determines usage context i.e. “view or edit” • … https://github.com/WP-API/WP-API/blob/master/docs/routes/routes.md
  • 18. Retrieve A Post {! "ID": 11297,! "title": "Post 19",! "status": "publish",! "type": "post",! "author": 1,! "content": "",! "parent": null,! "link": "http://example.com/2014/08/post-19/",! "format": "standard",! "slug": "post-19",! "guid": "http://example.com/2014/08/post-19/",! "excerpt": null,! "menu_order": 0,! "comment_status": "closed",! "ping_status": "open",! "sticky": false,! "meta": {},! "featured_image": null,! "terms": {}! } GET /wp-json/posts/<id>
  • 19. Edit A Post PUT /wp-json/posts/<id> curl -X PUT -H “Content-Type: application/json” -d ‘! {! "title": “Updated Title",! “content_raw": “Updated post content"! }! ‘ -u admin:password http://example.com/wp-json/posts/<id> We need to send a PUT request to this endpoint with our post data. Of course we must authenticate before doing this.
  • 20. Three ways to authenticate • Cookie Authentication (client side) • HTTP Basic Authentication • OAuth 1
  • 21. HTTP Basic Authentication First install the WP Basic Auth Plugin: https://github.com/WP-API/Basic-Auth Remember this piece of our cURL request? -u admin:password That’s HTTP Basic Authentication! Essentially we are authenticating by passing an HTTP header like this: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== Where that crazy looking string is username:password base64 encoded.
  • 22. HTTP Basic Authentication should only be used for testing!
  • 23. OAuth 1.0a First install the WP OAuth Plugin: https://github.com/WP-API/OAuth1 OAuth is outside of the scope of this talk. However, it should be used instead of HTTP Basic Auth when building external applications that interact with the API. Rather than giving someone an account on your site, you can give them temporary access with OAuth.
  • 24. Create A Post POST /wp-json/posts/ curl -X POST -H “Content-Type: application/json” -d ‘! {! "title": “Title",! “content_raw": “Post content"! }! ‘ -u admin:password http://example.com/wp-json/posts/ Notice we are using a POST request this time.
  • 25. Taxonomies GET /wp-json/taxonomies [! {! "name": "Categories",! "slug": "category",! "labels": {},! "types": { /* Registered post types */ },! "show_cloud": true,! "hierarchical": true,! "meta": {}! },! {! "name": "Tags",! "slug": "post_tag",! "labels": {},! "types": { /* Registered post types */ },! "show_cloud": true,! "hierarchical": false,! "meta": {}! }! }! ]
  • 26. Taxonomy GET /wp-json/taxonomies/<taxonomy> {! "name": "Categories",! "slug": "category",! "labels": {},! "types": { /* Registered post types */ },! "show_cloud": true,! "hierarchical": true,! "meta": {}! }
  • 27. Taxonomy Terms GET /wp-json/taxonomies/<taxonomy>/terms [! {! "ID": 1,! "name": "Books",! "slug": "books",! "description": "",! "parent": null,! "count": 1,! "link": "http://example.com/category/books/",! "meta": {}! },! {! "ID": 2,! "name": "Products",! "slug": "products",! "description": "",! "parent": null,! "count": 1,! "link": "http://example.com/category/products/",! "meta": {}! }! ]
  • 28. Build Your Own Routes and Endpoints WP API is very extensible (custom post types!) http://wp-api.org/guides/extending.html
  • 29. What can I do with the JSON REST API for WordPress?
  • 30. JavaScript Interact with your (or someone else’s) WordPress install with JavaScript. Backbone.js Client: https://github.com/WP-API/client-js ! ! Node.js Client: https://github.com/kadamwhite/wordpress-rest-api !
  • 31. Backbone.js • Backbone.js is a JavaScript framework that lets you structure code in terms of models, views, and collections. It works great with RESTful JSON API’s.
  • 32. _s_backbone • _s or underscores is a popular starter theme by Automattic: https://github.com/automattic/_s • _s_backbone is an _s fork that powers post loops using the WP API Backbone client
  • 34. What does this mean? • It means _s_backbone is a starter theme with infinite scroll built-in using the WP API Backbone client. • Infinite scroll is the concept of loading multiple rounds of entities without reloading the page. Let’s look at some code!
  • 35. This is some JavaScript you could add to a theme or plugin to display your site’s posts. You will first need to have JSON REST API for WordPress installed and the “wp-api” JavaScript dependency enqueued. functions.php: js/scripts.js:
  • 36. If you learned nothing so far, know this: You can do amazing things with the JSON REST API for WordPress. With core integration and ~23% of the web using this API in the near future, you will have much easier access to data across the web.
  • 37. Questions? @tlovett12! taylor.lovett@10up.com! taylorlovett.com We need to send a PUT request to this endpoint with our post data. Of course we must authenticate before doing this.