Positive Incline Mike Burrows (@asplake) moving on up, positively

August 3, 2009

One link to rule them all

Filed under: Uncategorized,Web Integration — Tags: , , — Mike @ 11:22 am

A quick demonstration of the described_routes discovery protocol is in order. It’s all done with link headers, one per resource.

Starting with some arbitrary resource in the application:

$ curl --silent --head http://localhost:3000/users/dojo | grep Link
Link: ; rel="describedby"; meta="ResourceTemplate"
$ curl --silent --head http://localhost:3000/described_routes/user?user_id=dojo | grep Link
Link: ; rel="index"; meta="ResourceTemplates"

So after the first HEAD request we have the location of the resource’s ResourceTemplate metadata; after the second we have the location of the site ResourceTemplates (plural) metadata.

A HEAD request to the site metadata location merely confirms (via the meta tag) what we already knew:

$ curl --silent --head http://localhost:3000/described_routes | grep Link
Link: ; rel="self"; meta="ResourceTemplates"

On the root resource, a single HEAD request links us to the site metadata location directly:

$ curl --silent --head http://localhost:3000 | grep Link
Link: ; rel="describedby"; meta="ResourceTemplates"

After that, it’s up to the client.

When you create a path-to client thus:

app = PathTo::DescribedRoutes::Application.discover("http://localhost:3000/users/dojo")

path-to discovers the site metadata and GETs it, specifying JSON as the acceptable format. The JSON response is converted to basic Ruby objects and used to initialize the Application object app. The client now knows the application’s resource structure:

app.users['dojo'].uri
=> "http://localhost:3000/users/dojo"

and we’re back where we started!

3 Comments

  1. […] http://positiveincline.com/?p=480 […]

    Pingback by Phil Archer (philarcher) 's status on Monday, 03-Aug-09 11:07:30 UTC - Identi.ca — August 3, 2009 @ 11:57 am

  2. […] Positive Incline Mike Burrows (asplake) moving on up « One link to rule them all […]

    Pingback by described_routes is Rack middleware « Positive Incline — August 4, 2009 @ 12:01 pm

  3. […] and by PathTo clients in order to discover and interact with application resources.  All of this works in Ruby already of course; my current personal project is to replicate it in Python with support […]

    Pingback by Small steps along my personal Python roadmap « Positive Incline — January 20, 2010 @ 1:25 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress