Blog.

by Jon Crosby

Release: CloudKit 0.9 - An Open Web JSON Appliance

How many lines of code does it take to deploy a fully discoverable, RESTful, GET-optimized, auto-versioned, JSON API?

Two. First, install the gem:

CloudKit is Rack middleware, so let’s create a rackup file called config.ru like this:

Fire it up with Thin, for example:

You now have a running JSON container managing collections of “notes” and “projects.” For the full REST API spec, see the CloudKit site. Don’t miss the curl tutorial while you’re there.

Let’s say we want to add both OpenID and OAuth support to this API. How many more lines of code?

Zero. Simply change “expose” to “contain” and you’re ready to go:

CloudKit is built around HTTP and JSON for the purpose of building efficient APIs quickly. It’s a bit like CouchDB with baked-in Open Web auth plus the entire spectrum of Rack middleware at its disposal. The automatic version history for each JSON document is provided as an aid for decentralized or occasionally-connected clients, allowing a progressive diff/merge against history to “catch up” in the case of conflicts.

Thanks to Rack, you can run CloudKit on its own or alongside other Rack-based apps or middleware components such as Rails, Merb, or Sinatra. Any requests outside of the named collection scopes or authentication endpoints are passed along to the next piece in the stack.

If you’re interested in hacking, the source is on GitHub.