microset

Lightweight microservices framework for NodeJS


Keywords
microservice, nodejs
License
MIT
Install
npm install microset@0.0.6

Documentation

microset

Codeship Status for jamro/microset npm version

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
  • Bundled set of services
    • Echo
    • HTTP Server
    • JSON-RPC Gateway
    • JSON-RPC Client
    • JSON Storage

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"};
  }
}

// create the container and register your service.
let container = new microset.ServiceContainer();
container.services.register(MyService);

// 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
container.startJsonRpcGateway({
  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.