1.0.1 • Published 7 years ago

unmon-router v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago
'Said Ummon to his disciples,
"However wonderful a thing is,
it may be that it is better
not to have it at all."

unmon-router

a minimalist, express-like router

Unmon-router implements a lightweight, middleware router. Its api makes it compatible with most express middleware.

Usage

var http = require('http');
var unmon = require('unmon-router');
var app = unmon();

// log all request URLs
app.route(/.*/, function (req, res, next) {
    console.log(req.url);
    next();
});

// handle API requests
app.route(/^\/api\//, function (req, res, next) {
    res.end('{}');
});

// serve 404s for everything else
app.route(/.*/, function (req, res) {
    res.statusCode = 404;
    res.end('404');
});

http.createServer(app.compile()).listen(3007);

API

The above example illustrates the basic API.

  1. initialize an app.
  2. push middleware to a stack with app.route.
  • unlike express, unmon expects the url pattern to be a regex, not a string
  • the middleware function should use the (request, response, callback) signature
  1. compile the app and pass it to the http module.

Install

With npm installed, run

$ npm install unmon-router

Acknowledgments

unmon-router was inspired by Expressjs.

License

ISC

1.0.1

7 years ago

1.0.0

7 years ago