0.5.0 • Published 10 years ago
http-router v0.5.0
http-router
router module for node.js
Installation
$ npm install http-router
Usage
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 test
Functions
route(req, res)
req
http.ServerRequest - http server request objectres
http.ServerResponse - http server response object
call added HTTP method callback functions.
get/post/put/delete/options/trace/connect/patch(path, cb)
path
string - request pathcb
function(req, res, next) - callback functionreq
http.ServerRequest - http server request objectres
http.ServerResponse - http server response objectnext
function() - call next function
return
HttpRouter - return this instance object.
add HTTP method callback function.
License
The MIT License. Please see LICENSE file.