Backbone and Cloudant
backbone.cloudant is a small library we've developed to make connecting to Cloudant from Backbone applications really easy. We hope it'll help others develop great web apps and would love to hear what people think of the first version, especially if they find bugs or have some feature requests.
Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
We've been using Backbone in a number of projects over the past months (and are planning on using it a lot more in the future). It's a great fit for working with Cloudant straight from the browser.
There are four obvious features for the backbone.cloudant library:
- minimal dependencies: ideally require nothing more than Backbone itself
- a base Model, configured to read/write directly to the database
- simplify Collections relating to the Cloudant feature set: views, searches and _all_docs
- a suitable change handler
I'm pleased to say that all of these features are in v0.0.1 of backbone.cloudant.
Because the Cloudant API is compatible with Apache CouchDB the code works with CouchDB, apart from where the feature set diverges. For example the SearchCollection is only supported against Cloudant because there's no native search feature in CouchDB. Everything else should work and have been tested against CouchDB.
Why not use an existing connector?
There are a lot of "connectors" available that hook Backbone up to a CouchDB backend, which of course work out of the box with Cloudant. These tend to override the Sync function, as suggested in the Backbone docs and allow you to talk to CouchDB or Cloudant from your Backbone app.
The Backbone docs describing the Sync function also say:
By default, it uses (jQuery/Zepto).ajax to make a RESTful JSON request and returns a jqXHR.
That means these connectors aren't really necessary. Backbone maps very nicely onto the REST API of CouchDB/Cloudant out of the box. In fact we've found these connectors tend to add complexity. We didn't want to make a connector like that, hence the barebones design of backbone.cloudant.