Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jack Lenox - Intro to the REST API - WordCamp Athens 2016

Jack Lenox - Intro to the REST API - WordCamp Athens 2016


WordPress Greek Community

November 19, 2016


  1. An introduc on to the WordPress REST API Jack Lenox

    (@jacklenox) WordCamp Athens 2016
  2. I Greece!

  3. 1. The case for a WordPress REST API

  4. What is a REST API?

  5. It stands for REpresenta onal State Transfer Applica on Programming

  6. Centred around verbs GET POST UPDATE PUT DELETE etc. Different

    ways to interact with your data
  7. Usually responds in XML or JSON format XML (Extensible Markup

    Language) HTML RSS JSON (JavaScript Object Notation)
  8. Why does WordPress need one?

  9. None
  10. MoMA in New York (c. 2009) Their developers wanted to

    use: WordPress as the CMS Ruby to build the front-end Why? I don't know... but they did
  11. None
  12. None
  13. None
  14. Internet of things

  15. So, what is the WordPress REST API?

  16. None
  17. None
  18. Merge meline WordPress 4.4 (8 December 2015) Infrastructure merged No

    endpoints WordPress 4.7 (due 6 December 2016) Endpoints merged!
  19. 2. How the WordPress REST API works (aka, what the

    heck is an endpoint?)
  20. End‐what? REST APIs interprets a URL, and return a response

    Not wildly different to RSS Sample request to fetch some posts: wc-athens.dev/wp-json/wp/v2/posts
  21. [ { "id": 1, "date": "2016-11-18T14:08:53", "date_gmt": "2016-11-18T14:08:53", "modified": "2016-11-18T14:08:53",

    "modified_gmt": "2016-11-18T14:08:53", "slug": "hello-world", "type": "post", "link": "http://wp-rest-api-demo.dev/2016/11/18/hello-wor "title": { "rendered": "Hello world!" }, "content": { "rendered": "<p>Welcome to WordPress. This is your fi "protected": false } } ]
  22. More endpoints... Single post: wc-athens.dev/wp-json/wp/v2/posts/1 All pages: wc-athens.dev/wp-json/wp/v2/pages All users:

    wc-athens.dev/wp-json/wp/v2/users All categories: wc-athens.dev/wp-json/wp/v2/categories
  23. Moar verbs! By default, our calls to the REST API

    are GET requests. But we can do a lot more: POST PUT UPDATE DELETE
  24. Authen ca on!

  25. A few ways to authen cate Basic Authen ca on

    Quick and dirty Cookie Authen ca on Good, especially for themes and plugins OAuth 1.0 A bit complicated, but versatile OAuth 2 Less complicated than OAuth 1, but requires HTTPS
  26. Brokered Authen ca on apps.wp-api.org

  27. Modifying endpoints

  28. 3. Uses for the WordPress REST API

  29. Custom wp‐admin interfaces Calypso HappyTables

  30. Mobile applica ons WordPress apps for iOS and Android Vienna

  31. Themes Picard Anadama Foxhound

  32. Plugins WooCommerce Syndication EDD

  33. Enterprise Guggenheim Quartz Google IO (not WordPress, but...)

  34. Very exci ng mes ahead!

  35. Further reading, and any ques ons? v2.wp-api.org WordPress.tv (search "REST

    API") javascriptforwp.com
  36. Ευχαριστώ πολύ! @jacklenox