Last active
December 22, 2015 02:28
-
-
Save tooxie/6403577 to your computer and use it in GitHub Desktop.
Defining RESTful APIs with Kolba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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