Sammy: RESTful Evented JavaScript

05 Nov 2009 | By Ric Roberts | Tags libraries JSON

Sammy is a jQuery-based javascript framework by Aaron Quint for building full-blown applications written purely in javascript. Sammy owes a lot to Sinatra, a lightweight DSL for creating Ruby web applications, but it’s more than just a straight javascript port: Sammy embraces javascript and jQuery conventions.

Much like Sinatra, Sammy revolves around the concept of REST routes. These consist of HTTP-style verbs (i.e. get, post, put etc), a path and a callback.

var app = $.sammy(function() {
  this.get('#/', function() {

Running the really simple sammy app above, and navigating to #/ would invoke the function and put the text ‘Kazam!’ in the main element of your page.

This is just the tip of the iceberg though: Sammy supports templating (via a plugin), so you can render pre-defined HTML templates in your apps. If only databases had a public REST interfaces and understood JSON, you could actually do away with the traditional web stack, and just let Sammy talk directly to your database. Hang on… CouchDB fits the bill! Aaron takes this idea further in this article on his blog.

Sammy is available on Github, and the repository includes some examples to get you started. There’s also some documentation here.

blog comments powered by Disqus