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

Jack Lenox - Intro to the REST API - WordCamp A...

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

WordPress Greek Community

November 19, 2016
Tweet

More Decks by WordPress Greek Community

Other Decks in Programming

Transcript

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

    (@jacklenox) WordCamp Athens 2016
  2. Usually responds in XML or JSON format XML (Extensible Markup

    Language) HTML RSS JSON (JavaScript Object Notation)
  3. 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
  4. Merge meline WordPress 4.4 (8 December 2015) Infrastructure merged No

    endpoints WordPress 4.7 (due 6 December 2016) Endpoints merged!
  5. 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
  6. [ { "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 } } ]
  7. 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
  8. Moar verbs! By default, our calls to the REST API

    are GET requests. But we can do a lot more: POST PUT UPDATE DELETE
  9. 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