microset
v0.0.6
Published
Lightweight microservices framework for NodeJS
Downloads
13
Readme
microset
Lightweight microservices framework for NodeJS. Production code does not include any node_module
dependencies.
Key Features
- Lighweight - zero
node_module
dependencies - Expose services API over HTTP (JSON-RPC)
- Client for frontend apps
- Service Registry
- Log management
- Configuration management
- Services running in separate processes
- Bundled set of services
- Directory
- Echo
- HTTP Server
- JSON-RPC Gateway
- JSON-RPC Client
- JSON Storage
- Static Content
Installation
Install microset from npm repository:
$ npm install microset --save
Usage Example
Create your service implementation in MyService.js
file:
const microset = require('microset');
// Your service implementation.
// It must extends microset.Service class.
class MyService extends microset.Service {
async init() {
// expose method to access them externally
this.expose('helloWorld');
}
// your logic comes here
async helloWorld() {
this.logger.info("Hello World!!!");
return {hello: "world"};
}
}
module.exports = MyService;
Create main entry point for your app index.js
:
const microset = require('microset');
// create the container and register your service.
let services = new microset.ServiceRegistry();
services.register('./MyService.js');
// start JSON-RPC gateway
// Your service will be available over JSON-RPC at
// http://localhost:8080/api/MyService
// Web client that you can use for tests is here:
// http://localhost:8080/client
microset.build.jsonRpcGateway(services, {
jsonRpc: {
apiPath: '/api',
webClientPath: '/client'
}
});
Run microset and your service:
$ node myservice.js
23:40:04 | MyService | INFO | Initialising MyService service...
23:40:04 | HttpServerService | INFO | Initialising HttpServerService service...
23:40:04 | JsonRpcGatewayService | INFO | Initialising JsonRpcGatewayService service...
23:40:04 | JsonRpcClientService | INFO | Initialising JsonRpcClientService service...
23:40:04 | MyService | INFO | Service MyService initialised.
23:40:04 | MyService | INFO | Exposing method helloWorld()...
23:40:04 | MyService | INFO | Service ready
23:40:04 | JsonRpcGatewayService | INFO | Service JsonRpcGatewayService initialised.
23:40:04 | JsonRpcGatewayService | INFO | Exposing method request()...
23:40:04 | JsonRpcGatewayService | INFO | Service ready
23:40:04 | JsonRpcClientService | INFO | Service JsonRpcClientService initialised.
23:40:04 | JsonRpcClientService | INFO | Exposing method getWebClient()...
23:40:04 | JsonRpcClientService | INFO | Exposing method getClientLib()...
23:40:04 | JsonRpcClientService | INFO | Service ready
23:40:04 | HttpServerService | INFO | HTTP server started: http://localhost:8080
23:40:04 | HttpServerService | INFO | Service HttpServerService initialised.
23:40:04 | HttpServerService | INFO | Exposing method request()...
23:40:04 | HttpServerService | INFO | Service ready
Visit http://localhost:8080/client, fill the form:
- Gateway URL: /api
- Service: MyService
- Method: helloWorld
- Parameters: []
and press submit to see results.
More examples
For more examples see example folder.