Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created August 1, 2011 06:43
Show Gist options
  • Save indexzero/1117668 to your computer and use it in GitHub Desktop.
Save indexzero/1117668 to your computer and use it in GitHub Desktop.
An example of a possible "resource" API in node.js
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);
});
};
@pacovell
Copy link

I updated my fork of this to show what I have in mind -- let's discuss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment