May 08, 2008

An OpenLibrary API Handshake With Yahoo Pipes

My blog reader this morning brought news of an API from OpenLibrary (via Dave Pattern), a strangely RESTful-JSON approach that expects json queries to be passed to the API via a URL... (not sure I've seen that before, such is the sheltered life I lead!?).

Like the Cohere API, the OpenLibrary API uses the idea of internal IDs as keys to access information about a particular resource... which is handy at times, but a pain at others...

For example, to look up the details of a book by ISBN, the following handshake is required: 1) ask the API for the ID of a book, given it's ISBN; 2) get the ID back; 3) lookup the book details using the ID.

So just to familiarise myself with the API, I thought a pipe was in order, and a quick half-hour hack later, here we are: a Yahoo pipe that will look up the details of a book, using the OpenLibrary API, given the book's ISBN. (Note that the pipe is, at the time of writing, not as complete as it could be - whilst it return return lots of data as JSON, the RSS is pretty bare. When I get a chance, I'll see about a pipe that will take the OpenLibrary JSON data and create some Dublin Core/RSS feed annotations using it.)

First up, build the URL to query the OpenLibrary API about the ID for a book with a given ISBN and fetch the JSON response from the API:

OpenLibrary API query builder

The next step is a fudge that hacks the API response to get the resource ID in a form we can make easy use of it. The Loop block actually takes the resource ID and gets the full record book data for it:

OpenLibrary - lookup details by ID

Here's the detail of the OpenLibrary record lookup pipe:

OpenLibrary book detail lookuop query builder

(At the current time, this pipe only emits JSON, not any vanilla RSS.)

I then start to tidy up the data that is returned from the book record lookup pipe to create an RSS feed (this bit is far from complete!):

OpenLibrary - make RSS

So there we have it - a bit of nested pipework that makes a couple of calls to the OpenLibrary API - the first to get an internal OpenLibrary ID for a given ISBN, the second to look up the details of the corresponding  book using the OpenLibrary ID.

All told, I reckon 40 mins plus 20 mins for this blog post...

Blogged with the Flock Browser

Tags: , ,

Posted by ajh59 at May 8, 2008 02:56 PM
Comments