Watzmann.Blog
Varying amounts of fiber

Sinatra Rabbit - a RESTful DSL

When we converted Deltacloud from
Rails to Sinatra,
we needed a way to conveniently write the controller logic for RESTful
routes with Sinatra. On a lark, I cooked up a DSL called ‘Rabbit’ that lets
you write things like

That makes supporting the common REST operations convenient, and allows us
to auto-generate documentation for the REST API. It has been very useful in
writing the
twofrontends
for Deltacloud.

The DSL has lots of features, for example, validation of input parameters,
conditionally allowing additional parameters, describing subcollections,
autogenerating HEAD and OPTIONS routes and controllers, and many more.

Michal Fojtik has pulled that code out of Deltacloud and
extracted it into its own github project as
sinatra-rabbit In the process,
there were quite a few dragones to slay: for example, in Deltacloud we
change what parameters some operations can accept based on the specific
backend driver. For example, in some clouds, it is possible to inject
user-defined data into instances upon launch. In Deltacloud, the logic of
what routes to turn on or off is based on introspecting the current driver,
which means that Deltacloud’s Rabbit knows about drivers. That, of course,
has to be changed for the standalone sinatra-rabbit. Michal just added
route conditions that look like

Hopefully, sinatra-rabbit will grow to the point where we can remove our
bundled implementation from Deltacloud, and use the standalone version;
there’s still a couple of features missing, but with enough people
sending patches, it can’t be very long now ;)