$30 off During Our Annual Pro Sale. View Details »

WCNYC2014

 WCNYC2014

Ryan McCue

August 03, 2014
Tweet

More Decks by Ryan McCue

Other Decks in Programming

Transcript

  1. The WordPress

    JSON REST API
    WordCamp NYC 2014
    Ryan McCue
    @rmccue

    View Slide

  2. wp-api.org

    View Slide

  3. Meet the Team

    View Slide

  4. What is the REST API?

    View Slide

  5. Three Parts:

    “JSON REST API”

    View Slide

  6. JSON
    {
    "ID": 4,
    "title": "My Awesome Post",
    "content": "This is my awesome content!"
    }
    JavaScript Object Notation
    • Supported by basically everything
    • Human readable
    • Standard

    View Slide

  7. REST
    Actions applied to Resources
    Create POST
    Read GET
    Update PUT
    Delete DELETE
    Uses HTTP actions:
    Representational State Transfer

    View Slide

  8. REST
    Representational State Transfer
    /posts
    /posts/4
    /posts
    /posts/4
    /posts/4
    GET
    GET
    POST
    PUT
    DELETE
    Action

    (Verb)
    Resource

    (Object)

    View Slide

  9. API
    Application Programming Interface
    A way to access and manipulate your data

    View Slide

  10. API
    Or extend as needed!
    GET POST PUT DELETE
    Posts ✔ ✔ ✔ ✔
    Pages ✔ ✔ ✔ ✔
    Custom Post Types ✔ ✔ ✔ ✔
    Post Meta ✔ ✔ ✔ ✔
    Media ✔ ✔ ✔ ✔
    Comments ✔ ✔
    Taxonomies/Terms ✔ ✔ ✔ ✔
    Users ✔ ✔ ✔ ✔

    View Slide

  11. Why do we need it?

    View Slide

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

    View Slide

  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

    View Slide

  14. How do we use it?

    View Slide

  15. {
    "name": "WP API Dev",
    "description": "Just another WordPress site",
    "URL": "http://local.wpapi.dev",
    "routes": {},
    "authentication": [],
    "meta": {}
    }
    /wp-json/
    GET

    View Slide

  16. [{
    "ID": 110,
    "title": "Testing sticky",
    "status": "publish",
    "type": "post",
    "author": {},
    "content": "this should be stuck as a post. Stuck on you.\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": "this should be stuck as a post. Stuck on you.\n”,
    "comment_status": "open",
    "sticky": true,
    "meta": {},
    "featured_image": null,
    "terms": {}
    }]
    /wp-json/posts
    GET

    View Slide

  17. {
    "ID": 1,
    "title": "Hello World!",
    "status": "publish",
    "type": "post",
    "author": {},
    "content": "Welcome to WordPress. This is your first post. Edit
    or delete it, then start blogging!\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": "Welcome to WordPress. This is your first post. Edit
    or delete it, then start blogging!\n",
    "comment_status": "open",
    "meta": {},
    "featured_image": null,
    "terms": {}
    }
    /wp-json/posts/1
    GET

    View Slide

  18. How can we use it?

    View Slide

  19. Install the Plugin

    View Slide

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

    View Slide

  21. Where can we learn
    more?

    View Slide

  22. Resources
    JSON REST API Plugin:

    github.com/WP-API/WP-API
    !
    OAuth1 Authentication Plugin: 

    github.com/WP-API/OAuth1

    Basic Authentication Plugin: 

    github.com/WP-API/Basic-Auth
    !
    API Console:

    github.com/WP-API/api-console
    JSON REST API

    View Slide

  23. Resources
    JS Client:

    github.com/WP-API/client-js
    !
    PHP Client: 

    github.com/WP-API/client-php 

    WP-CLI Client: 

    github.com/WP-API/client-cli
    JSON REST API Clients

    View Slide

  24. Have questions?
    Ryan McCue
    @rmccue
    wp-api.org
    github.com/WP-API/WP-API
    speakerdeck.com/rmccue/wcnyc2014

    View Slide