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

The WordPress REST API: A game changer for WordPress

Silvan Hagen
November 18, 2016

The WordPress REST API: A game changer for WordPress

The WordPress REST API is finally coming to Core in 4.7 (December 2016). This talk is a brief introduction on the concept of REST and the WP REST API. Additionally it's a showcase of the exciting new things you'll be able to build on top of the WordPress REST API.

Talk held at WordCamp Geneva 2016: https://2016.geneva.wordcamp.org

Additional links to the slides: https://goo.gl/N4RQ6N

Silvan Hagen

November 18, 2016
Tweet

More Decks by Silvan Hagen

Other Decks in Technology

Transcript

  1. The WordPress REST API
    A game changer for WordPress @ #wcgva

    View Slide

  2. 27.1% of The Web
    Now available in a RESTful way.

    View Slide

  3. Silvan Hagen
    Co-Founder & WordPress
    Developer @wearerequired
    @neverything

    View Slide

  4. What is A REST API?
    Trust me it’s easier than it sounds.

    View Slide

  5. REpresentational State Transfer
    - Not any smarter yet? Well me neither ¯\_(ツ)_/¯
    - It’s about resources & a little bit about verbs
    - Uses HTTP methods in a specific way

    View Slide

  6. REST: Let’s have a look
    GET /friends => Returns a Collection of friends
    GET /friends/joe => Returns a single friend
    GET /friends/new => Could be a form to add a friend

    View Slide

  7. The HTTP methods in REST
    GET /friends => READ
    POST /friends => CREATE
    PUT /friends => UPDATE
    DELETE /friends => DELETE
    The famous CRUD

    View Slide

  8. What about REST and WordPress?
    GET /wp-json/wp/v2/posts => Collection of Posts
    GET /wp-json/wp/v2/posts/ => Singular Post
    GET /wp-json/ => Allows discovering the API

    View Slide

  9. REST & WordPRESS
    A little history lesson about the REST API.

    View Slide

  10. How did we get here?
    - Started as GSoC project in 2013 by Ryan McCue
    - Infrastructure merged into WP 4.4 in 2015
    - Content Endpoints merged into WP 4.7 in 2016

    View Slide

  11. What’s in it?
    There are a few more concepts in the WP REST API.

    View Slide

  12. API Discovery via Response Header
    - In the response header of a request:
    Link: ;
    rel="https://api.w.org/"

    View Slide

  13. API Discovery via Element
    - Added to the of your HTML:

    View Slide

  14. API Feature Discovery - Authentication
    - The API will tell you how to authenticate

    View Slide

  15. API Feature Discovery - Extensions
    - The API will tell you what namespaces exist:

    View Slide

  16. API Feature Discovery - Combined

    View Slide

  17. API Routes

    View Slide

  18. API Routes

    View Slide

  19. Linking using HAL
    - Uses HAL (Hypertext Application Language) to link related
    resources

    View Slide

  20. Embed Related Resources
    - Add ?_embed to any API Request URI

    View Slide

  21. Relax:
    The Crazy Part is over,
    let’s look at Examples

    View Slide

  22. What Can You Build?
    A few examples and ideas.

    View Slide

  23. In The WP-Admin
    https://wordpress.org/plugins/dashboard-directory-size/

    View Slide

  24. View Slide

  25. In Your Theme

    View Slide

  26. Standalone Web Apps/Sites

    View Slide

  27. DATA Heavy Things

    View Slide

  28. APPS APPS APPS
    https://github.com/joehoyle/vienna

    View Slide

  29. So are you ready for the WP
    REST API?

    View Slide

  30. Already Built Something?

    View Slide

  31. Some more Ideas
    - Mobile Apps
    - Other technologies can consume WP in a standardised way
    - New Admin Interfaces
    - Meta Boxes in the backend
    - All the lame admin-ajax.php stuff
    - WP_List_Tables
    - Customizer
    - Data heavy widgets
    - Comments (cool once comment type is merged)
    - Links & more: https://goo.gl/N4RQ6N

    View Slide

  32. Thanks for Having Me!
    Questions?

    View Slide