SlideShare a Scribd company logo
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.

More Related Content

PPTX
The JSON REST API for WordPress
PDF
Beyond The Browser - Creating a RESTful Web Service With WordPress
PPTX
Best Practices for WordPress in Enterprise
PPTX
Best Practices for Building WordPress Applications
PDF
You Got React.js in My PHP
PPTX
Building native mobile apps with word press
PDF
OpenERP and Perl
PPTX
Webinar: AngularJS and the WordPress REST API
The JSON REST API for WordPress
Beyond The Browser - Creating a RESTful Web Service With WordPress
Best Practices for WordPress in Enterprise
Best Practices for Building WordPress Applications
You Got React.js in My PHP
Building native mobile apps with word press
OpenERP and Perl
Webinar: AngularJS and the WordPress REST API

What's hot (20)

PDF
Best Practices for WordPress
PPT
Develop webservice in PHP
PDF
Scalable web application architecture
KEY
Advanced WordPress Development Environments
PPTX
Building Your First App with MongoDB
PPTX
Put a little Backbone in your WordPress
PDF
CouchDB for Web Applications - Erlang Factory London 2009
PDF
The never-ending REST API design debate
PPTX
Introduction to Plugin Programming, WordCamp Miami 2011
PDF
Differential Sync and JSON Patch @ SpringOne2GX 2014
PDF
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails
PDF
Introducing RaveJS: Spring Boot concepts for JavaScript applications
PPTX
REST API Best Practices & Implementing in Codeigniter
PDF
Transforming WordPress Search and Query Performance with Elasticsearch
PDF
REST Web API with MongoDB
PDF
Introduction to CouchDB
PDF
Understanding and testing restful web services
PDF
Djangocon 2014 angular + django
PDF
Software Development with Open Source
PPTX
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
Best Practices for WordPress
Develop webservice in PHP
Scalable web application architecture
Advanced WordPress Development Environments
Building Your First App with MongoDB
Put a little Backbone in your WordPress
CouchDB for Web Applications - Erlang Factory London 2009
The never-ending REST API design debate
Introduction to Plugin Programming, WordCamp Miami 2011
Differential Sync and JSON Patch @ SpringOne2GX 2014
Hypermedia: The Missing Element to Building Adaptable Web APIs in Rails
Introducing RaveJS: Spring Boot concepts for JavaScript applications
REST API Best Practices & Implementing in Codeigniter
Transforming WordPress Search and Query Performance with Elasticsearch
REST Web API with MongoDB
Introduction to CouchDB
Understanding and testing restful web services
Djangocon 2014 angular + django
Software Development with Open Source
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
Ad

Viewers also liked (20)

PDF
WordPress & A Mobile App
PDF
マルチパブリッシング プラットフォームとしてのWordPress
PDF
Demystifying the REST API
PPT
WordPress and the Enterprise
PPTX
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
PDF
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...
PDF
PHP classの教室
PDF
第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会
PDF
CodaでClipを使ってWordPress開発を早くするススメ。
PDF
WP REST API
PDF
WordCamp Tokyo 2012 Concept
KEY
WordPress中級者への道!テンプレートタグはどう動くのか!?
PDF
8時間耐久CakePHP2 勉強会
PDF
WordPress REST API hacking
PDF
How to get your theme on Top 15 Popular Themes at WordPress.org
PDF
Child Theme
PDF
An easy guide to Plugin Development
PDF
Javantura v4 - True RESTful Java Web Services with JSON API and Katharsis - M...
PDF
Getting Started With WP REST API
PPTX
Design Beautiful REST + JSON APIs
WordPress & A Mobile App
マルチパブリッシング プラットフォームとしてのWordPress
Demystifying the REST API
WordPress and the Enterprise
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
WordCamp Seoul: WordPress Based web services in Japan / WordCamp 서울 : 일본에서 워드...
PHP classの教室
第三章ナビゲーション &lt; 第4回デザイニング・インターフェース勉強会
CodaでClipを使ってWordPress開発を早くするススメ。
WP REST API
WordCamp Tokyo 2012 Concept
WordPress中級者への道!テンプレートタグはどう動くのか!?
8時間耐久CakePHP2 勉強会
WordPress REST API hacking
How to get your theme on Top 15 Popular Themes at WordPress.org
Child Theme
An easy guide to Plugin Development
Javantura v4 - True RESTful Java Web Services with JSON API and Katharsis - M...
Getting Started With WP REST API
Design Beautiful REST + JSON APIs
Ad

Similar to JSON REST API for WordPress (20)

PDF
JSON REST API for WordPress
PDF
AtlasCamp2014: Introducing the Confluence REST API
PDF
Designing a beautiful REST json api
KEY
WordPress APIs
PDF
Finding Restfulness - Madrid.rb April 2014
PDF
Building Better Web APIs with Rails
PDF
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
PDF
2.28.17 Introducing DSpace 7 Webinar Slides
PDF
Web Services
PDF
Building APIs in an easy way using API Platform
PDF
Have You Seen Spring Lately?
PDF
REST easy with API Platform
PDF
FOXX - a Javascript application framework on top of ArangoDB
PPTX
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
PDF
ITB2016 - Building ColdFusion RESTFul Services
PDF
Using the new WordPress REST API
PPTX
Rest in practice
PDF
Be a microservices hero
PDF
WordCamp Wilmington 2017 WP-API Why?
PDF
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
JSON REST API for WordPress
AtlasCamp2014: Introducing the Confluence REST API
Designing a beautiful REST json api
WordPress APIs
Finding Restfulness - Madrid.rb April 2014
Building Better Web APIs with Rails
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
2.28.17 Introducing DSpace 7 Webinar Slides
Web Services
Building APIs in an easy way using API Platform
Have You Seen Spring Lately?
REST easy with API Platform
FOXX - a Javascript application framework on top of ArangoDB
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
ITB2016 - Building ColdFusion RESTFul Services
Using the new WordPress REST API
Rest in practice
Be a microservices hero
WordCamp Wilmington 2017 WP-API Why?
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...

More from Taylor Lovett (6)

PDF
WordPress Acceptance Testing, Solved!
PDF
Best practices-wordpress-enterprise
PDF
Wordpress search-elasticsearch
PDF
Modernizing WordPress Search with Elasticsearch
PPTX
What You Missed in Computer Science
PPTX
Saving Time with WP-CLI
WordPress Acceptance Testing, Solved!
Best practices-wordpress-enterprise
Wordpress search-elasticsearch
Modernizing WordPress Search with Elasticsearch
What You Missed in Computer Science
Saving Time with WP-CLI

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
Encapsulation theory and applications.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
1. Introduction to Computer Programming.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
A comparative analysis of optical character recognition models for extracting...
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
SOPHOS-XG Firewall Administrator PPT.pptx

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! [email protected]! taylorlovett.com We need to send a PUT request to this endpoint with our post data. Of course we must authenticate before doing this.