Top Banner
WordPress JSON API Intro Wil Brown @LimeCanvas www.limecanvas.c om
15

An Intro to the WordPress JSON API

Dec 14, 2014

Download

Technology

Lime Canvas

An introduction to the new WordPress JSON API.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An Intro to the WordPress JSON API

WordPress JSON API

Intro

Wil Brown@LimeCanvas

www.limecanvas.com

Page 2: An Intro to the WordPress JSON API

What is JSON?

@LimeCanvas #wpsyd

Java Script Object Notation

Lightweight data exchange format akin to XML

Easy for humans and machines to read & write

Page 3: An Intro to the WordPress JSON API

JSON Simple Example

@LimeCanvas #wpsyd

{ "first": "Bob", "last": "Bobbley", "sex": "M", "interests": ["Particle Physics", " Beer", "Hacking" ] };

Page 4: An Intro to the WordPress JSON API

JSON Nested Example

@LimeCanvas #wpsyd

{

"first": "Bob", "last": "Bobbley", "sex": "M", "interests": [" Particle Physics", " Beer", "Hacking" ] "favourites" : { "colour" : "Purple", "food" : "Pizza" }};

Page 5: An Intro to the WordPress JSON API

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

Page 6: An Intro to the WordPress JSON API

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.

Page 7: An Intro to the WordPress JSON API

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+

Page 8: An Intro to the WordPress JSON API

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)

Page 9: An Intro to the WordPress JSON API

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.

Page 10: An Intro to the WordPress JSON 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.

Page 11: An Intro to the WordPress JSON API

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

Page 12: An Intro to the WordPress JSON API

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.

Page 13: An Intro to the WordPress JSON API

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/

Page 14: An Intro to the WordPress JSON API

Image Credits

@LimeCanvas #wpsyd

[1] wikipedia.com

Page 15: An Intro to the WordPress JSON API

Questions Anyone?

@LimeCanvas

@LimeCanvas #wpsyd