1.0.0-beta.3 • Published 7 years ago

micromachine v1.0.0-beta.3

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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

}
1.0.0-beta.3

7 years ago

1.0.0-beta.1

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago