Created
August 1, 2011 06:43
-
-
Save indexzero/1117668 to your computer and use it in GitHub Desktop.
An example of a possible "resource" API in node.js
This file contains 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 util = require('util'), | |
resourceLib = require('our-new-resource-lib'); | |
var SomeResource = function (options) { | |
resourceLib.Resource.call(this, options); | |
// | |
// Setup any other application specific state. | |
// | |
// | |
// Require authorization for GET, PUT, POST, and DELETE | |
// | |
this.authorize('GET', 'PUT', 'POST', 'DELETE') | |
// | |
// Setup this resource to use CouchDB. | |
// | |
this.use('couch') | |
}; | |
util.inherits(SomeResource, resourceLib.Resource); | |
SomeResource.prototype.get = function (params, callback) { | |
var self = this; | |
// | |
// Here you would access the super "classes" `._get()` method | |
// and perform any default translations | |
// | |
this._get(params.name, function (err, instance) { | |
// | |
// Do something like map the instance properties, etc., | |
// then invoke the callback via the render function | |
// | |
self.render(instance, callback); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated my fork of this to show what I have in mind -- let's discuss