0.1.1 • Published 11 years ago
match-route v0.1.1
match-route
Match a request against a object of routes
installation
component/component
$ component install [--dev] ramitos/match-route
npm
$ npm install [--save/--save-dev] match-route
example
var mr = require('match-route'),
assert = require('assert');
mr({
method: 'PUT',
url: '/user/admin?q1=3&q2=t'
}, {
'get': {
'/user/:id/age': 'some string',
'/': true
},
'post': {
'/user/:id/:age': 45
},
'put': {
'/:type/:subtype': 'other string'
},
'delete': {
'/user/:id': false
}
}, function (value, route, params, query) {
assert(route === '/:type/:subtype');
assert(params.subtype === 'admin');
assert(value === 'other string');
assert(params.type === 'user');
assert(query.q1 === '3');
assert(query.q2 === 't');
});
license
MIT