http-routing

0.1.0 • Public • Published

http routing

Simple, unobtrusive routing of HTTP requests (a url and a verb) for the server or a browser.

Started as a research project in routing without regular expressions.

example

var router = require('http-routing');

// create a new index of routes
var routes = [];

// add route to the index
routes.push(router.route('GET', '/ping', 'A'));

// add another route to the index
routes.push(router.route('GET', '/echo/:word', 'B'));

router.match('GET', '/anything');	// undefined
router.match('POST', '/ping');	// undefined

router.match('GET', '/ping');
/*
{
	method: 'GET',
	signature: '/ping',
	params: [],
	value: 'A',
	args: [],
	query: '',
}
*/

router.match('GET', '/echo/bam?a=b');
/*
{
	method: 'GET',
	signature: '/echo/:',
	params: [ 'word' ],
	value: 'B',
	args: [ 'bam' ],
	query: 'a=b',
}
*/

Install

 npm install http-routing

Test

npm test

Readme

Keywords

Package Sidebar

Install

npm i http-routing

Weekly Downloads

8

Version

0.1.0

License

MIT

Last publish

Collaborators

  • thomas-jensen