http-router
router module for node.js
Installation
$ npm install http-router
Usage
var http = router = routes = router; // or routes = new router; routes ; http;
$ curl -X GET http://localhost:3000Hello, World!$ curl -X POST http://localhost:3000POST!$ curl -X GET http://localhost:3000/111/222key1: 111key2: 222$ curl -X GET http://localhost:3000/unknownNot Found$ curl -X PATCH http://localhost:3000Not Implemented
Test
$ npm install$ npm test
Functions
http-router#createRouter()
return
Router - new Router instance.
Return new Router instance. It's similar to new require('http-router')
.
Router#route(req, res)
-
req
http.IncomingMessage - IncomingMessage object -
res
http.ServerResponse - ServerResponse object -
return
boolean - return false if not called any callback functions.
Call appended callback functions if match to route's path. Call empty path's callback if not match to any route's path.
Router#options/get/head/post/put/delete/trace/connect/patch([path], callback)
-
path
string|function|object - request path -
callback
function(req, res, next)|undefined - callback functionreq
http.IncomingMessage - IncomingMessage objectres
http.ServerResponse - ServerResponse objectnext
function() - call next callback function
-
return
Router - return own instance.
Append path and callback function.
License
The MIT License. Please see LICENSE file.