Skip to content

Instantly share code, notes, and snippets.

@tooxie
Last active December 22, 2015 02:28
Show Gist options
  • Save tooxie/6403577 to your computer and use it in GitHub Desktop.
Save tooxie/6403577 to your computer and use it in GitHub Desktop.
Defining RESTful APIs with Kolba
var Kolba = require('kolba');
var app = new Kolba.App();
// RESTful
var lyricsResource = new Kolba.Resource({
get: function() {
// Fetch from somewhere
return json;
}
});
var artistResource = new Kolba.Resource({
subResources: {
'lyrics': lyricsResource
},
get: function(slug, id) {
// Fetch artist
return json;
},
post: function(data) {
// Create object
}
});
/*
* This would create the following resources:
* /artists/
* /artists/:id/
* /artists/:id/lyrics/
*/
app.addResource('artists', artistResource);
app.run(9001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment