0.5.0 • Published 12 years ago
http-router v0.5.0
http-router 
router module for node.js
Installation
$ npm install http-routerUsage
var http = require('http'),
router = require('http-router'),
routes = new router;
routes
.get('/', function(req, res, next) {
res.write('Hello,');
return next();
})
.get('/', function(req, res, next) {
res.write(' World');
return next();
})
.get('/', function(req, res, next) {
res.end('!\n');
})
.post('/', function(req, res, next) {
res.write('PO');
return next();
})
.post('/', function(req, res, next) {
res.write('ST');
return next();
})
.post('/', function(req, res, next) {
res.end('!\n');
});
http.createServer(function(req, res) {
routes.route(req, res);
}).listen(3000);$ curl -X GET http://localhost:3000
Hello, World!
$ curl -X POST http://localhost:3000
POST!Test
$ npm install
$ npm testFunctions
route(req, res)
reqhttp.ServerRequest - http server request objectreshttp.ServerResponse - http server response object
call added HTTP method callback functions.
get/post/put/delete/options/trace/connect/patch(path, cb)
pathstring - request pathcbfunction(req, res, next) - callback functionreqhttp.ServerRequest - http server request objectreshttp.ServerResponse - http server response objectnextfunction() - call next function
returnHttpRouter - return this instance object.
add HTTP method callback function.
License
The MIT License. Please see LICENSE file.