1. Dec 17th, 2007

    DeHorrible: RESTifying SimpleDB

    1999 called, they want their CGI scripts back.

    I think that pretty much sums up people’s response to the horror that is the SimpleDB API. By which, I mean the few of us who can tell what’s wrong with it. Which sadly is not that many people.

    But offending it is, and much like MySpace, I can’t bring myself to use it. So I decided to do something about it. Subbu came up with an interesting proposal for a RESTful API for SimpleDB:

    In this exercise, my starting point was Amazon’s definition of the REST API, which I refactored into a RESTful version without breaking the usage pattern. Several variations of this approach are possible, but the key point to make is that (a) it is important to identify what the resources are, and (b) then think of mapping various operations into known HTTP verbs for the API to be RESTful, without losing focus on the net benefits of building an API over HTTP. This is not hard.

    Not hard at all, Subbu. I took that idea and ran with it, creating DeHorrible.

    DeHorrible is a Rails proxy that RESTifies SimpleDB. Or if you insist, GETStifies your resources to use SimpleDB. Either way, it will keep your sensibilities intact. I ended up with a slightly different resource mapping:

    • POST /domains, using either name query parameter or name in body, returning 201 with URL in Location.
    • GET /domains, with optional limit and token query parameters, which brings you back a list of URLs, with which you can …
    • DELETE /domains/[name].
    • GET /domains/[name], which takes the optional query parameters query, limit and token, and brings you back a list of URLs, one for each found item.
    • POST /domains/[name] to create a new item, returning 201 with the URL in Location. Requires item name and attributes, either URL-encoded, JSON hash, or XML document.
    • GET /domains/[name]/items/[name] retrieves all attributes associated with that item.
    • PUT /domains/[name]/items/[name] updates (replaces) attributes with new values.
    • POST /domains/[name]/items/[name] adds new attribute values.
    • DELETE /domains/[name]/items/[name] does what you think it will.

    Once you get into attributes (attributes/[name]) you can do a few more funky things like retrieve, replace and append individual attribute values, and delete an attribute of all its value, or a given value (attributes/[name]/[value]).

    It uses HTTP Basic authentication, so plug your AWS ID as login name, secret key as password, and rock:

    curl http://your_id:key@localhost:3000/domains -X POST -d HelloDomain
    curl http://your_id:key@localhost:3000/domains/HelloDomain

    So there you go. SimpleDB de-horrified. Now we can all sleep better.

    The code is available here.

    1. Dec 17th, 2007

      James Governor’s Monkchips » “It would be hard to convince me Amazon needs IBM”. Bonus Erlang dorkery

      [...] Funnily enough this is *already* happening in the shape of the DeHorrible Rails proxy. [...]

    2. Dec 17th, 2007

      Labnotes RESTifies SimpleDB « Object neo = neo Object

      [...] RESTifies SimpleDB Posted on December 17, 2007 by bairos Assaf Arkin made a RESTification of Amazon ’s SimpleDB API, which was recently launched claiming to be RESTful. He published [...]

    3. Dec 17th, 2007

      SnapLogic Blog » Does a REST API on the Web even matter ?

      [...] Bill notes the Amazon SimpleDB ‘REST’ API isn’t really REST. Over on REST discuss, others note the same thing. In fact, there’s already a Rail’s proxy that provides an alternative, RESTful interface. [...]

    4. Dec 17th, 2007

      Matthew King

      I noodled, ineffectively, over the weekend with this idea, although I was wondering how far I could get in providing a REST interface using solely nginx with rewrites.

    5. Dec 17th, 2007

      links for 2007-12-17 « Object neo = neo Object

      [...] Labnotes » DeHorrible: RESTifying SimpleDB RESTification of Amazon ’s SimpleDB. Amazing and valuable feedback! (tags: amazon api restful soa) [...]

    6. Jan 20th, 2008

      Martin Rehfeld

      Funny enough, I just stumbled accross this, right _after_ finishing similar work on my AWS SDB Proxy Plugin. I took a slightly different approach, focusing on connecting to ActiveResource models, though.

    7. Mar 31st, 2008

      links for 2007-12-19

      [...] Labnotes » DeHorrible: RESTifying SimpleDB (tags: amazon rest rubyonrails simpledb) [...]

    Your comment, here ⇓

    Or using OpenID