This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

micromachine

1.0.0-beta.3 • Public • Published

Installation

npm install micromachine --save

Creating a new service

const Micromachine = require('micromachine');

class SayHelloService extends Micromachine.Service {
  
  // Implement your microservice using Single Responsability Principle
  execute() {
    if (false) {
      throw new Error('Something went wrong');
    }
    return { message: `Running microservice saying hello to ${this.firstname}` };
  }
}

SayHelloService.inputs = {
  required: ['first_name'],
  optional: ['last_name'],
};

Using this service synchronously

SayHelloService.run({ first_name: 'Ludo' })

Cherry on top, the run method returns a Promise.

SayHelloService.run({ first_name: 'Ludo' })
  .then((data) => { console.log(data); });
  .catch((error => { console.error(error); }));

Using this service as a HTTP Endpoint

You can simply declare in your index.js

let endpoint = new SayHelloService();
endpoint.runtime = new Micromachine.HTTPEndpoint({
  port: 5000,
  path: '/hello',
});

endpoint.run()
  .then((data) => { console.log(data); });
  .catch((error => { console.error(error); }));

Using this service on AWS Lambda

You can simply declare in your index.js

// index.js

exports.handler = function(event, context) {
  let lambda = new SayHelloService();
  lambda.runtime = Micromachine.AWSLambda();

  lambda.run({ event: event, context: context })
   .then((data) => { console.log(data); });
   .catch((error => { console.error(error); }));

}

Package Sidebar

Install

npm i micromachine

Weekly Downloads

0

Version

1.0.0-beta.3

License

MIT

Last publish

Collaborators

  • lgalabru