It is just a proof-of-concept middleware to monkey-patch Moleculer Broker in order to add pattern-matching routing for action calls.
npm install icebob/moleculer-pattern
Install middleware
const { ServiceBroker } = require("moleculer");
const PatternMiddleware = require("../../index");
// Create broker
const broker = new ServiceBroker({
logger: console,
});
broker.use(PatternMiddleware(broker));
Create service with patterns
broker.createService({
name: "a",
actions: {
first: {
pattern: {
a: 0,
b: "x"
},
handler(ctx) {
return "Hello ${ctx.params.name}";
}
}
}
});
Call a service
const res = await broker.act({ a: 0, b: "x", name: "John" });
console.log(res); // "Hello John"
$ npm test
In development with watching
$ npm run ci
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.
The project is available under the MIT license.
Copyright (c) 2018 MoleculerJS