Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dimapaloskin/micro-chain
🤝 Helps to build chains from your micro services.
https://github.com/dimapaloskin/micro-chain
async await javascript micro microservice microservices node
Last synced: 3 months ago
JSON representation
🤝 Helps to build chains from your micro services.
- Host: GitHub
- URL: https://github.com/dimapaloskin/micro-chain
- Owner: dimapaloskin
- Created: 2017-03-11T09:07:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T09:18:47.000Z (over 4 years ago)
- Last Synced: 2024-10-08T16:17:07.179Z (4 months ago)
- Topics: async, await, javascript, micro, microservice, microservices, node
- Language: JavaScript
- Homepage:
- Size: 3.29 MB
- Stars: 24
- Watchers: 3
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micro - micro-chain - Builds flexible requests chains and pass them into micro handler. (Modules / Utilities)
README
# micro-chain
> Helps to build chains from your [micro](https://github.com/zeit/micro/) services.
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![Build Status](https://travis-ci.org/dimapaloskin/micro-chain.svg?branch=master)](https://travis-ci.org/dimapaloskin/micro-chain)
[![Greenkeeper badge](https://badges.greenkeeper.io/dimapaloskin/micro-chain.svg)](https://greenkeeper.io/)### Overview
Module provides simple ability to build chains like:
```
first.api.your-domain.com
-> second.api.your-domain.com
-> third.api.your-domain.com
-> final.api.your-domain.com
```### Install
```bash
npm install --save micro-chain
```### Example
**index.js**
```js
const chain = require('micro-chain');
const options = {
micro: 'app.js', // or just your micro async function required before
location: /\/some-path$/, // optional. chain will be executed only if request url matched
chain: [{
target: 'account.api.your-domain.com',
mergeJson: true // response json will be merged with
// request json and will be passed down the chain
}, {
target: 'storage.api.your-domain.com/s3/save',
mergeJson: true,
allowedStatuses: [200, 201], // array of allowed statuses.
// request will rejected if target's response has not included status
// rejected response will be equal target's response// transformRequestBody will modify request data and return result if declared
// receive Buffer
transformRequestBody: body => {
if (!body || !body.length) return body;
body = JSON.parse(body);
delete body.secret;
return body;
},// transformReponseBody will modify response body if declared
// receive Buffer
transformReponseBody: body => {
if (!body || !body.length) return body;
body = JSON.parse(body);
body.newProp = true;
delete body.token;
return body;
}
}, {
// if host is not declared will extract host from original request
target: '/notify'
}, {
target: 'some-stuff.api.your-domain.com',
sendOriginalBody: true // modifed body passed down the chain.
// use this option if you want send original data
}]
};
module.exports = chain(options);
```Run:
```bash
micro index.js
```### See in action
Clone this repo
Install dependencies
```bash
npm install
```Build project
```bash
npm run build
```Run `npm start`
Make POST request
```bash
curl http://localhost:3000/public -XPOST -d '{"what": "you want", "message": "ping"}'
```### Author
[Dmitry Pavlovsky](http://palosk.in)