https://github.com/icebob/moleculer-pattern
[PoC] Pattern-matching middleware for Moleculer
https://github.com/icebob/moleculer-pattern
moleculer pattern-matching
Last synced: 22 days ago
JSON representation
[PoC] Pattern-matching middleware for Moleculer
- Host: GitHub
- URL: https://github.com/icebob/moleculer-pattern
- Owner: icebob
- License: mit
- Created: 2018-04-12T09:42:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-21T09:44:40.000Z (almost 7 years ago)
- Last Synced: 2025-02-03T23:35:04.033Z (3 months ago)
- Topics: moleculer, pattern-matching
- Language: JavaScript
- Homepage:
- Size: 74.2 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pattern matching feature [](https://www.npmjs.com/package/moleculer-pattern)
It is just a proof-of-concept middleware to monkey-patch Moleculer Broker in order to add pattern-matching routing for action calls.## Features
## Install
```
npm install icebob/moleculer-pattern
```## Usage
**Install middleware**
```js
const { ServiceBroker } = require("moleculer");
const PatternMiddleware = require("../../index");// Create broker
const broker = new ServiceBroker({
logger: console,
});broker.use(PatternMiddleware(broker));
```**Create service with patterns**
```js
broker.createService({
name: "a",
actions: {
first: {
pattern: {
a: 0,
b: "x"
},
handler(ctx) {
return "Hello ${ctx.params.name}";
}
}
}
});
```**Call a service**
```js
const res = await broker.act({ a: 0, b: "x", name: "John" });
console.log(res); // "Hello John"
```# Test
```
$ npm test
```In development with watching
```
$ npm run ci
```# Contribution
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.# License
The project is available under the [MIT license](https://tldrlegal.com/license/mit-license).# Contact
Copyright (c) 2018 MoleculerJS[](https://github.com/moleculerjs) [](https://twitter.com/Icebobcsi)