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



Ryan McCue

August 03, 2014

More Decks by Ryan McCue

Other Decks in Programming


  1. The WordPress
 JSON REST API WordCamp NYC 2014 Ryan McCue

  2. wp-api.org

  3. Meet the Team

  4. What is the REST API?

  5. Three Parts:

  6. JSON { "ID": 4, "title": "My Awesome Post", "content": "This

    is my awesome content!" } JavaScript Object Notation • Supported by basically everything • Human readable • Standard
  7. REST Actions applied to Resources Create POST Read GET Update

    PUT Delete DELETE Uses HTTP actions: Representational State Transfer
  8. REST Representational State Transfer /posts /posts/4 /posts /posts/4 /posts/4 GET

 (Verb) Resource
  9. API Application Programming Interface A way to access and manipulate

    your data
  10. API Or extend as needed! GET POST PUT DELETE Posts

    ✔ ✔ ✔ ✔ Pages ✔ ✔ ✔ ✔ Custom Post Types ✔ ✔ ✔ ✔ Post Meta ✔ ✔ ✔ ✔ Media ✔ ✔ ✔ ✔ Comments ✔ ✔ Taxonomies/Terms ✔ ✔ ✔ ✔ Users ✔ ✔ ✔ ✔
  11. Why do we need it?

  12. XML-RPC Hugely complicated: (WordPress for iPhone Trac)

  13. Jetpack API Easy for developers Works with Javascript easily (JSON-based)

    Requires Jetpack active Depends on WordPress.com Does not work for local development Cannot control access to certain apps
  14. How do we use it?

  15. { "name": "WP API Dev", "description": "Just another WordPress site",

    "URL": "http://local.wpapi.dev", "routes": {}, "authentication": [], "meta": {} } /wp-json/ GET
  16. [{ "ID": 110, "title": "Testing sticky", "status": "publish", "type": "post",

    "author": {}, "content": "<p>this should be stuck as a post. Stuck on you.</p>\n", "link": "http://local.wpapi.dev/testing-sticky/", "date": "2014-06-02T10:47:39-05:00", "modified": "2014-06-02T10:47:39-05:00", "format": "standard", "slug": "testing-sticky-2", "guid": "http://local.wpapi.dev/testing-sticky-2/", "excerpt": "<p>this should be stuck as a post. Stuck on you.</p>\n”, "comment_status": "open", "sticky": true, "meta": {}, "featured_image": null, "terms": {} }] /wp-json/posts GET
  17. { "ID": 1, "title": "Hello World!", "status": "publish", "type": "post",

    "author": {}, "content": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>\n", "link": "http://local.wpapi.dev/hello-world/", "date": "2014-04-18T15:14:46-05:00", "modified": "2014-05-02T01:26:30-05:00", "format": "standard", "slug": "hello-world", "guid": "http://local.wpapi.dev/?p=1", "excerpt": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>\n", "comment_status": "open", "meta": {}, "featured_image": null, "terms": {} } /wp-json/posts/1 GET
  18. How can we use it?

  19. Install the Plugin

  20. Backwards Compatible Right Now: Version 1 Coming Soon: Version 2

    Full Compatibility
  21. Where can we learn more?

  22. Resources JSON REST API Plugin:
 github.com/WP-API/WP-API ! OAuth1 Authentication Plugin:

 Basic Authentication Plugin: 
 github.com/WP-API/Basic-Auth ! API Console:
 github.com/WP-API/api-console JSON REST API
  23. Resources JS Client:
 github.com/WP-API/client-js ! PHP Client: 

    WP-CLI Client: 
 github.com/WP-API/client-cli JSON REST API Clients
  24. Have questions? Ryan McCue @rmccue wp-api.org github.com/WP-API/WP-API speakerdeck.com/rmccue/wcnyc2014