What is a REST API? - What is the WP REST API? - A bit of history - Who is using it? - How to use it - What you can do with it - suggestions - examples
Interface - method for an application to talk to another app/service/language - REpresentational State Transfer - enables access & manipulation of a textual representation of a web-based resource - coined by Roy Fielding in his 2000 dissertation
request is independent of each other, and all information to complete the task needs to be included in one go 2. Cacheable 3. Uniform interface URI identifies the resource → method performs operation on resource → operation is implicit in the URL e.g., http://mybadass.blog/delete/product/coffee resource method
separation of client & server where the server doesn’t care about the state of the server and the client doesn’t need to store information 5. Layered Doesn’t matter if the server is primary, or an intermediary 6. Response is in a hypermedia format (optional) - XML is a hypermedia format because it conveys meaning within the markup - JSON is sometimes - API author needs to structure output in a RESTful way
uses WP back-end, Ruby front-end resulting in JSON API plugin Jan 2013 first code for WP REST API by Ryan McCue on Github Google SoC 2014 v1 stable: robust, but not ready for core (no internal API, difficult to extend) Feb 2015 started v2: Ryan McCue, Rachel Baker, Joe Hoyle, Daniel Bachhuber schemas posts, pages, media, terms, users controller, server Not to scale! Apr 2015 v2b1 May 2015 speed increase, custom response fields, pagination v2b2 Oct 2015 infrastructure merged into core! Jun 2013 Dec 2016 WP 4.7 API merged into core!
the URL you need - discovery URL is revealed in the head of your site 2. Construct the URL with resource and method 3. JSON reponse is returned 4. Parse information <link rel='https://api.w.org/' href='http://kristarella.blog/wp-json/' /> GET http://kristarella.blog/wp-json/wp/v2/posts
- On your site - suggest search terms for your visitors - pagination - archives/portfolio filter - replace admin-ajax.php tasks - Search a site from anywhere - streamline workflows - Quick post - Parse information into other APIs in any language - integrate signups with Salesforce, Meetup, Mailchimp - Display real-time sales data