This example illustrates microservice chaining / proxying where one microservice uses another microservice as part of its implementation.
This package defined two services:
- PublicHelloService: which defines a simple
/helloendpoint that delegates to our PrivateHelloService - PrivateHelloService: which defines a simple
/helloendpoint that returns{ msg: "Hello world!" }
Flow
Client PublicHelloService PrivateHelloService
|
| GET /hello
| ---------------------------> /hello
| GET /hello
| -----------------------------> /hello
|
200: { msg: "Hello world!" } |
<----------------------------------|
|
200: { msg: "Hello world!" } |
|<--------------------------------|
We encourage you to clone the git repository so you can play around with the code.
$ git clone -b carbon-0.7 [email protected]:carbon-io-examples/example__hello-world-service-chaining.git
$ cd example__hello-world-service-chaining
$ npm install
Start the private service:
$ node lib/PrivateHelloServiceStart the public service (order does not matter):
$ node lib/PublicHelloServiceFor cmdline help:
$ node lib/PublicHelloService -hor
$ node lib/PrivateHelloService -hTo access the /hello endpoint on the public service:
$ curl localhost:8888/hello
{ msg: "Hello world!" }
This example comes with a simple unit test written in Carbon.io's test framework called TestTube. It is located in the test directory.
$ node test/HelloServiceTest
or
$ npm test
To generate documentation using aglio, install it as a devDependency:
$ npm install -D --no-optional aglio
Using --no-optional speeds up aglio's install time significantly. Then generate the docs using these commands:
$ node lib/PrivateHelloService gen-static-docs --flavor aglio --out docs/private-api.html$ node lib/PublicHelloService gen-static-docs --flavor aglio --out docs/public-api.htmlView current documentation