match-route

Match a request against a object of routes

npm install match-route
20 downloads in the last month

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

npm loves you