Jump to content

My RESTful API For NodeJS (snooze)


MrFish
 Share

Recommended Posts

I've recently been doing AngularJS work and love how it's organized. I tried to find something similar for NodeJS but after searching I've only found the basics to setup your own framework (like expressjs) but nothing that actually provides a simple modular framework. So I've started to write my own.

 

snooze is a restful framework that is simple and modular. It's focused around building a restful api but not necessarily the nodejs version of something like apache. Every request is handled by a controller, is validated through validators, and is processed by a service. A framework suitable for web/mobile/tablet apps.

 

snooze is released under GPL so please feel free to share, change, and share it. Also share it.

 

Have a look at the examples and post your criticisms. I wrote this simple framework for my projects but I'm excited that it may help others.

 

https://github.com/iamchairs/snooze

https://github.com/iamchairs/snooze-stdlib

snooze.module('myServer', ['snooze-stdlib']) // inject the snooze-stdlib module    .route('get', '/users/:username', { // define the route        controller: 'UserCtrl', // what controller should handle this route        action: 'getUserByUsername', // what action to perform on this route        validator: 'GetUsername' // before processing this action what validation should occur    })    .controller('UserCtrl', function(User) { // inject the User service        return {            getUserByUsername: function(res, options) {                User.getUserByUsername(options.query.username).then(function(username) {                    res.send(200, username);                }).fail(function(err) {                    res.send(500, err);                });            }        };    })    .service('User', function($q) { // inject the $q service        return {            getUserByUsername: function() {                var deferred = $q.defer();                deferred.resolve('iamchairs');                return deferred.promise;            }        };    })    .validator('GetUsername', function($validator) { // inject the validator service        return function(deferred, req) {            if($validator.isLength(req.query.username, 2, 32)) {                deferred.resolve(); // resolve (valid request)            } else {                deferred.reject([400, 'Username must be between 2 and 32 characters']); // reject (invalid request)            }        }    });
Edited by MrFish
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 2 weeks later...

I don't understand why you would post this here. They don't even do nodejs tutorials. They are sellout that work with ie behind the scene.

if you don't have anything constructive to add, please don't post it.

 

There's no harm in showing off work, but maybe it should have been in the critiques sub forum, whatever. Either way, you're not one to judge.

Link to comment
Share on other sites

if you don't have anything constructive to add, please don't post it. There's no harm in showing off work, but maybe it should have been in the critiques sub forum, whatever. Either way, you're not one to judge.

I don't mean any harm toward it.... Wait! Maybe if we just start posting about node they'll put up a node tutorial!!!!Um yeah let talk more on this. So MrFish, what dependency does this have?I more aim toward using the core modules.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...