KEMBAR78
WP REST API - Adding Your Own Endpoint | PDF
WP REST API:
Adding Your Own Endpoint
Keanan Koppenhaver
http://levelupwp.net
https://www.facebook.com/levelupwp
http://github.com/kkoppenhaver
Who Am I?
• WordPress Developer at doejo for 3 years
• Worked on WP sites large (XX,XXX posts) and
small (5 simple pages)
• Have recently been using just pieces of the
WP REST API in production
Why are we here today?
• Learn a little about the WP REST API
• See some real world examples
• Learn which pieces of the API are available in
core
• Learn how to create our own endpoint
Questions?
Ask them anytime in the chat box below.
How did the REST API
come about?
• Proposed just after the WP Community Summit in
2012
• JSON over XML because of how it maps to
programming language constructs
• REST because the REST paradigm matches up
well with the CMS structure
• Merged* into Core on October 8, 2015 

(https://core.trac.wordpress.org/changeset/34928)
Source: https://youtu.be/tV4IuS_KnvU?t=19m24s
WP REST API in the wild
• ustwo.com
• WP Live Search
• A “Digital Newspaper” with the WP API
• WP Powered Mobile Apps
• Any many more…
Demo: ustwo.com
Demo: ustwo on Github
Is the WP REST API part of
WP Core?
• Yes*
• Infrastructure is in core
• Prebuilt endpoints aren’t in core
• We can create our own endpoints without an
additional plugin
• If we want all the endpoints we need a plugin
What does the plugin give us?
• Endpoints on posts, pages, revisions, media,
post types, post statuses, comments,
taxonomies, categories, tags and users
• Can be enabled for CPT or custom taxonomy
• For a full list, see the reference
And without the plugin?
• No endpoints available, but they can be
created
• Step 1: Create a function to return the
necessary data
• Step 2: Register with register_rest_route
• Step 3: Flush Rewrite Rules
• Step 4: Profit!
Step 1
Create a function to return the necessary data
Step 2
Register with register_rest_route
Step 3
Flush Rewrite Rules
Step 4
Profit!
Q&A
Keanan Koppenhaver
http://levelupwp.net
https://www.facebook.com/levelupwp
http://github.com/kkoppenhaver

WP REST API - Adding Your Own Endpoint

  • 1.
    WP REST API: AddingYour Own Endpoint Keanan Koppenhaver http://levelupwp.net https://www.facebook.com/levelupwp http://github.com/kkoppenhaver
  • 2.
    Who Am I? •WordPress Developer at doejo for 3 years • Worked on WP sites large (XX,XXX posts) and small (5 simple pages) • Have recently been using just pieces of the WP REST API in production
  • 3.
    Why are wehere today? • Learn a little about the WP REST API • See some real world examples • Learn which pieces of the API are available in core • Learn how to create our own endpoint
  • 4.
    Questions? Ask them anytimein the chat box below.
  • 5.
    How did theREST API come about? • Proposed just after the WP Community Summit in 2012 • JSON over XML because of how it maps to programming language constructs • REST because the REST paradigm matches up well with the CMS structure • Merged* into Core on October 8, 2015 
 (https://core.trac.wordpress.org/changeset/34928) Source: https://youtu.be/tV4IuS_KnvU?t=19m24s
  • 6.
    WP REST APIin the wild • ustwo.com • WP Live Search • A “Digital Newspaper” with the WP API • WP Powered Mobile Apps • Any many more…
  • 7.
  • 8.
  • 9.
    Is the WPREST API part of WP Core? • Yes* • Infrastructure is in core • Prebuilt endpoints aren’t in core • We can create our own endpoints without an additional plugin • If we want all the endpoints we need a plugin
  • 10.
    What does theplugin give us? • Endpoints on posts, pages, revisions, media, post types, post statuses, comments, taxonomies, categories, tags and users • Can be enabled for CPT or custom taxonomy • For a full list, see the reference
  • 11.
    And without theplugin? • No endpoints available, but they can be created • Step 1: Create a function to return the necessary data • Step 2: Register with register_rest_route • Step 3: Flush Rewrite Rules • Step 4: Profit!
  • 12.
    Step 1 Create afunction to return the necessary data
  • 13.
    Step 2 Register withregister_rest_route
  • 14.
  • 15.
  • 16.