micro-chain
Helps to build chains from your micro services.
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
npm install --save micro-chain
Example
index.js
const 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 { if !body || !bodylength return body; body = JSON; delete bodysecret; return body; } // transformReponseBody will modify response body if declared // receive Buffer { if !body || !bodylength return body; body = JSON; bodynewProp = true; delete bodytoken; 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 ; moduleexports = ;
Run:
micro index.js
See in action
Clone this repo
Install dependencies
npm install
Build project
npm run build
Run npm start
Make POST request
curl http://localhost:3000/public -XPOST -d '{"what": "you want", "message": "ping"}'