an intro to the wordpress json api
DESCRIPTION
An introduction to the new WordPress JSON API.TRANSCRIPT
What is JSON?
@LimeCanvas #wpsyd
Java Script Object Notation
Lightweight data exchange format akin to XML
Easy for humans and machines to read & write
JSON Simple Example
@LimeCanvas #wpsyd
{ "first": "Bob", "last": "Bobbley", "sex": "M", "interests": ["Particle Physics", " Beer", "Hacking" ] };
JSON Nested Example
@LimeCanvas #wpsyd
{
"first": "Bob", "last": "Bobbley", "sex": "M", "interests": [" Particle Physics", " Beer", "Hacking" ] "favourites" : { "colour" : "Purple", "food" : "Pizza" }};
What Is An API?
@LimeCanvas #wpsyd
Application Programming Interface
A set of functions that allow you to interact with the underlying application.– Read data– Write data– Ask to perform a task
WordPress API Examples
@LimeCanvas #wpsyd
get_blog_info( ‘name’ )Returns the name of the blog from General Settings
the_content()Returns the post content inside the WordPress loop. Used in most theme templates.
Why The Need?
@LimeCanvas #wpsyd
1st use of WordPress = Blogging platform2003-2008 (ish)
2nd use of WordPress = CMS (Content Management System)
2008 – 2013 (ish)
3rd use of WordPress = Application Framework2013/14+
Application Framework?
@LimeCanvas #wpsyd
Not a blog. Not a CMS.
It is WordPress being used as the back-end “system” that other “web” applications can be built upon.
Web apps need to:– get data– send data– ask framework to perform tasks (remember slide 4)– validate who’s asking (WordPress security)
What’s the Difference?
@LimeCanvas #wpsyd
Traditionally web apps were/are WordPress sites
Now, web apps can be written in anything– Node.js– .net– HMTL/PHP (Laravel)
..while using WordPress as the back-end data store and API.
JSON API – Two Modes
@LimeCanvas #wpsyd
Operates in two modes: implicit and explicit.
• Implicit mode is triggered by setting the json query var to a non-empty value on any WordPress page. The content that would normally appear on that page is returned in JSON format.
• Explicit mode is triggered by setting json to a known method/function string.
JSON API – Implicit
@LimeCanvas #wpsyd
Implicit examples• http://www.example.org/?json=1• http://www.example.org/?p=47&json=1• http://www.example.org/tag/security-issues/?json=1
Content for existing page is returned in JSON format rather than a web page.e.g.Return all posts with tag “security-issues” and list them on an external site
JSON API – Explicit
@LimeCanvas #wpsyd
Explicit examples• http://www.example.org/?json=get_recent_posts• http://www.example.org/?json=get_post&post_id=47• http://www.example.org/?json=get_tag_posts&tag_slug=security-issues
These all call functions rather than existing web page URLs.
All returned in JSON format.
Available When?
@LimeCanvas #wpsyd
Slated for WordPress 4.1 – December 2014
Where can you find out more?GitHub: https://github.com/WP-API/WP-API
Plugin: http://wordpress.org/plugins/json-api/
Image Credits
@LimeCanvas #wpsyd
[1] wikipedia.com
Questions Anyone?
@LimeCanvas
@LimeCanvas #wpsyd