0.5.0 • Published 10 years ago

http-router v0.5.0

Weekly downloads
58
License
-
Repository
github
Last release
10 years ago

http-router Build Status

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 object
  • res 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 path
  • cb function(req, res, next) - callback function

    • req http.ServerRequest - http server request object
    • res http.ServerResponse - http server response object
    • next function() - call next function
  • return HttpRouter - return this instance object.

add HTTP method callback function.

License

The MIT License. Please see LICENSE file.

0.5.0

10 years ago

0.4.2

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago