node.js rest server maker
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Documentation.md
LICENSE
README.md
drest.js
package.json

README.md

dREST

A node.js REST framework library

Install

npm install drest

See Documentation for more information

Example

Establish API methods

    var api = {
      user: {
			eyeColor_auth : function (passthrough) {
				passthrough.check(1);
			},
            getEyeColor : function (handler) {
    			handler.respond({eye_color:"green"});
    		},
    		setEyeColor: function (handler) {
                var color = JSON.parse(handler.data).eyecolor;
    			handler.respond({response:"eye color set to "+color});
    		}
    	}
    }

Create a router

    var drest = require("drest");
    
    var router = drest.createRouter(8100,"127.0.0.1");
    
    router.addRoute({
    	method:"get",
    	path:"user/{number}/eyecolor",
    	authLevel:1,
    	action:api.user.getEyeColor,
		authAction:api.user.eyeColor_auth
    });
    
    router.addRoute({
    	method:"post",
    	path:"user/{number}/eyecolor",
    	action:api.user.setEyeColor
    });
    
    router.setAuthLayer(
    	function(passthrough) {
    		passthrough.check(1);
    	}
    );