JSON REST APIs for WordPress

St. Louis WordPress Developer Meetup
07/07/14
Alex Rodriguez

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. -  json.org

What is REST?

Representational State Transfer...

It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used.
REST is an architecture style for designing networked applications. The idea is that, rather than using complex mechanisms such as RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.

REST  & CRUD

(Create/Read/Update/Delete) 
The four basic functions of persistent storage...

  • RESTful applications use HTTP requests to: 
    • GET (read)
    • POST (create)
    • PUT (update) 
    • DELETE (delete)

Why not use XML?

  • It's not the 90's anymore bro...
    • Smaller message size
      • JSON is more compact and can be easily loaded in JavaScript.
    • More structural information in the document
    • Can easily distinguish between:
      • Number 1 and the string "1" as numbers, strings (and Booleans) are represented differently in JSON.
      • Single items and collections of size one (using JSON arrays).
    • Easier to represent a null value

XML vs JSON


Why does my WP site need an API?


  • Expose your sites data  to the world!
    • Mobile Web 
    • Native Apps
    • Syndication 
    • Embeds 

IT'S...


JSON REST API  is slated for WordPress 4.1 Release

What are my options?

  • JSON REST API (WP API)
    • https://wordpress.org/plugins/json-rest-api/
      • Requires https://github.com/WP-API/OAuth1 for AUTH
  • Jetpack REST API 
    • http://jetpack.me/support/json-api/
  • Thermal API
    • http://wordpress.org/plugins/thermal-api/
  • ROLL YOUR OWN!





DEMO


Building 

By Alex Rodriguez

Loading comments...

More from Alex Rodriguez