REST API for WordPress

“Everything should be made as simple as possible, but not simpler.” A. Einstein

It is not that much I started tinkering about WordPress, and they publish a very interesting API for the site.
Following a well-established path, the site is a REST one. I would like to develop some code around it.
For now I show a very little snippet, in Python:

import urllib2
f = urllib2.urlopen('http://public-api.wordpress.com/rest/v1/sites/33534099/posts/43/?pretty=true/')
print f.read(100000)

If you own a nice copy of Python on your PC (that I warmly suggest), you can just call it with the simple
python
command. In the python environment you can then copy and paste the previous snippet, a row at a time, or you can create a file and make python execute it.
The result is a JSON description of data. What is Jason? We’ll see sooner or later: for now, let’s define it as a means to describe an object in a very direct manner.
For today please just observe the REST-ivity 🙂 of the call. If you look at the URL, you can clearly understand the structure of the request: it is a hierarchical description of something you want to GET.
It’s not by chance I am using the word “GET”: with REST you return to the very beginning of HTTP, (W3C specs) using just GET, POST, DEL and (guess!) PUT as basic verbs. Talking deeply about that would take us very far, for the moment let’s admire the clarity of the call.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s