Data routing largely inspired on express routing pattern but decoupled from the request / response paradigm
- Handles routes to be used on all cases.
- Handles routes to be used when the data as a specifc property.
- Handles routes to be used when the data as a property set to a specific value.
- Handles routes to be used when the data as a property with a value matching a specific regex pattern.
- Each route callback receives the evaluated data as first argument and a "next" callback as second argument.
- Every route can invoke the "next" callback argument to resolve the next valid route.
var DataRouter = require('data-router');
var dataRouter = new DataRouter();
dataRouter.register(function (data, next) {
console.log('Data:', data);
next();
});
dataRouter.register('foo', function (data, next) {
console.log('Data with property "foo":', data);
next();
});
dataRouter.register('foo', 'bar', function (data, next) {
console.log('Data with property "foo" set to "bar":', data);
next();
});
dataRouter.register('foo', /ba/ig, function (data, next) {
console.log('Data with property "foo" conaining the /ba/ pattern:', data);
next();
});
var data = {
foo: 'bar',
payload: {
bogus: 'stuff',
name: 'jhon doe'
}
}
dataRouter.resolve(data);