Skip to content

Object Data routing largely inspired on express routing pattern but decoupled from the request / response paradigm

Notifications You must be signed in to change notification settings

Darkhounds/data-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

data-router

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.

Initialize the router

var DataRouter = require('data-router');
var dataRouter = new DataRouter();

Register a route to be used on all cases

dataRouter.register(function (data, next) {
	console.log('Data:', data);

	next();
});

Register a route based on a property name:

dataRouter.register('foo', function (data, next) {
	console.log('Data with property "foo":', data);

	next();
});

Register a route based on a property exact value

dataRouter.register('foo', 'bar', function (data, next) {
	console.log('Data with property "foo" set to "bar":', data);

	next();
});

Register a route based on a property value partial match:

dataRouter.register('foo', /ba/ig, function (data, next) {
	console.log('Data with property "foo" conaining the /ba/ pattern:', data);

	next();
});

Apply existing routes on data object:

var data = {
	foo: 'bar',
	payload: {
		bogus: 'stuff',
		name: 'jhon doe'
	}
}

dataRouter.resolve(data);

About

Object Data routing largely inspired on express routing pattern but decoupled from the request / response paradigm

Resources

Stars

Watchers

Forks

Packages

No packages published