Getting started
Everything needed to bootstrap a first gateway with Nodegate is explained here.
Installation
Assuming you have already installed Node.js, create a directory and init your application:
$ mkdir mygateway
$ cd mygateway
Use the npm init
command to create a package.json
file for your application:
$ npm init
This command promps you for a number of things. Simply hit RETURN to accept the defaults for most of
them. Leave index.js
as the entry point of your application.
$ entry point: (index.js)
Now install Nodegate and save it in the dependencies list.
$ npm install nodegate --save
See the npm documentation for the full list of commands available with npm.
The main concept
The concept of Nodegate is simple: you create a gateway
with routes
defined executing
workflows
composed of workers
.
Here is an exemple of a gateway responding, with only one request, user and gist data from the
GitHub API:
const nodegate = require('nodegate');
const { aggregate } = require('nodegate/workers');
const gateway = nodegate();
gateway.route({
method: 'get',
path: '/:user',
workflow: [
aggregate('get', '/users/{params.user}'),
aggregate('get', '/users/{params.user}/gists', { target: 'gists' }),
],
});
gateway.listen(8080);
How does it work?
When a request is handled by Nodegate, a container
is created, this container is automatically
filled with different kind of data like the body
of the request. At the end of the workflow, this
container body
will be sent as the response.
This means a route without workflow will simply respond with the body of the request.
To fulfill the role of microservice orchestrator, Nodegate is shipped with dozens of workers you can configure into workflows to execute all the needed operations before responding. The workflows executes the configured workers synchronously.
Workflows can embed other workflows but will still be executed synchronously. The worker
executeAsynchronously
allow to execute two workflows aynchronously.