Skip to content
Match a request against a object of routes
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
test
.gitignore
.npmignore
.travis.yml
component.json
package.json
readme.md

readme.md

deprecated

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

Something went wrong with that request. Please try again.