HTTP/WebSocket Client (JavaScript) for Enapso Micro-Services. This module generate instances from remote micro-services public APIs, benefiting developers with the best possible "easy to use" interface.
npm install --save enapso-microservice-client
For this example we will use a production installation of the Enapso Enterprise Server, this is the Enapso Dash platform. The library use ES6 Promise based APIs.
- Creating the micro-service generator instance:
const MicroServiceGenerator = require('enapso-microservice-client');
const generator = new MicroServiceGenerator({
url: 'https://dash.innotrade.com/http',
username: 'guest',
password: 'guest'
});
// using WebSocket connection
const generator = new MicroServiceGenerator({
url: 'wss://heprdlxdemo01.innotrade.com',
username: 'guest',
password: 'guest'
});
2. Preparing generator:
```js
generator.open().then(() => {
// generator is ready for use...
}).catch(console.error);
- Generating a micro-service instance (In this case the EnapsoOntology micro-service):
let EOS;
generator.getService('EnapsoOntology').then((response) => {
EOS = response;
}).catch(console.error);
- Then, just invoke some methods (full example here)...
EOS.ontology.list({
offset: 0,
length: 50
}).then((response) => {
console.log(response);
}).catch(console.error);
- Join all together using a more elegant way, the co library:
const co = require('co');
const MicroServiceGenerator = require('enapso-microservice-client');
const generator = new MicroServiceGenerator({
url: 'https://dash.innotrade.com/http',
username: 'guest',
password: 'guest'
});
co(function *(){
// prepare connection
yield generator.open();
// generate service
let EOS = yield generator.getService('EnapsoOntology');
// call methods...
let response = yield EOS.ontology.list({
offset: 0,
length: 50
});
//...
//... finally when all the work is done, close the connection
yield generator.close();
})
let config = {};
config.url = 'https://dash.innotrade.com/http'; // the Enapso Enterprise Server connection URL
config.username = 'guest'; // login username
config.password = 'guest'; // login password
config.autoSyncTimeout = 500; // timeout used by the HttpClient to automatically pull messages from the server. Min value: 400ms
- Automated test-cases generation and execution.
$ git clone git@github.com:innotrade/enapso-microservice-client.git
$ cd enapso-microservice-client/
$ npm install
$ npm test