The WordPress REST API

C9a5478931da1bbdcc0be2800daa2915?s=47 Jack Lenox
January 13, 2015

The WordPress REST API

A talk that I gave at WordPress Cumbria in Kendal on Tuesday 13 January 2015.

C9a5478931da1bbdcc0be2800daa2915?s=128

Jack Lenox

January 13, 2015
Tweet

Transcript

  1. THE WORDPRESS REST API

  2. @jacklenox

  3. WHAT IS A REST API?

  4. REST API • REST stands for REpresentational State Transfer •

    API stands for Application Programming Interface • Probably the optimal word in all of this is Interface • A REST API gives you a new way of accessing your blog/site’s data
  5. The PHP API • Gives you ‘the loop’ • the_post(),

    the_title(), the_content(), the_date() etc etc. • It’s how developers have interacted with WordPress since day one • The problem here is that you pretty much have to use PHP
  6. THE REST API GIVES US OPTIONS

  7. HOW?

  8. A sample request

  9. The WordPress REST API • Several have popped up over

    the years • The now-official WordPress.org one has been forked from a plugin called ‘JSON API’ • This was first released in the plugin repository in 2009 • It was built as part of a project for the MoMA in New York. The project used Ruby on Rails. They had a Ruby on Rails frontend and a WordPress backend. • Due in WordPress core at some point (hopefully this year)
  10. SO WHY THE WAIT?

  11. None
  12. JavaScript has gotten HUGE • Node.js & npm • Backbone

    • Angular • Ember • React
  13. – Trek Glowacki, Core Team, Ember “Since the start of

    the web, for every interaction there have been two supercomputers involved. The supercomputer sitting in front of you and the supercomputer in a data centre somewhere. We have barely begun to take advantage of that supercomputer sitting in front of you.”
  14. SPAS SINGLE PAGE APPLICATIONS

  15. What is an SPA? • As opposed to multipage web

    application • Has only one initial page load • When done well, provides a more continuous, fluid user experience
  16. None
  17. The times are a-changin’ • This is nothing new •

    WordPress themes and plugins have been steadily doing more and more • It is relatively straightforward to have SPA elements within a multipage web application • Backbone has been included in WordPress core since 2012
  18. None
  19. So what can I actually do with the REST API?

    • REST APIs centre around a series of verbs • GET, POST, PUT, DELETE • GET posts/pages/comments etc. • Edit and add posts/pages/comments via POST • DELETE posts/pages/comments etc.
  20. It’s extensible

  21. None
  22. None
  23. FIN

  24. Useful links… wp-api.org github.com/WP-API/WP-API