0.2.3 • Published 7 years ago

agnostic-router v0.2.3

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

Agnostic Router

Route without Express and friends

Installation

Bower

bower install

Node

npm install

Usage

Load in Node.js:

var router = require('agnostic-router')();

Load in browser:

var router = Router();

router.use(function(request, respond, next) {
	console.log("All requests will pass through here");
	next();
});

router.use('/papers', function(request, respond, next) {
	console.log("This should not be triggered at all");
	next();
});

router.use('/books', function(request, respond, next) {
	console.log("All requests under /books will pass through here");
	next();
});

router.method('request', '/books/mybook', function(request, respond, next) {
	console.log("Requests to /books/mybook will pass through here");
	respond(null, "ok");
});

router.route('request', '/books/mybook', {}, function(error, response) {
	console.log("RESPONSE", error, response);
}, function() {
	console.log("This will be triggered if none of the routers are triggered");
});

// Build a path
var generated = router.path('/books/:category/:title', {category: 'mycategory', title: 'mytitle'});

Testing

mocha test/*
0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.2

8 years ago

0.0.1

9 years ago