# micromachine

> Microservices toolbox for Humans.

Latest version **1.0.0-beta.3** (published 2017-10-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install micromachine
pnpm add micromachine
yarn add micromachine
bun add micromachine
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.3 |
| Published | 2017-10-19 |
| First published | 2016-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ludovic Galabru |
| Maintainers | lgalabru |
| Keywords | microservice, microservices, endpoint, endpoints, hapi, h2o2, gateway, lambda, aws |

## Links

- npm: https://www.npmjs.com/package/micromachine
- npm.io page: https://npm.io/package/micromachine

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0-beta.3 (latest) — 2017-10-19
- 1.0.0-beta.1 — 2016-12-15
- 0.0.7 — 2016-12-09
- 0.0.6 — 2016-12-07
- 0.0.5 — 2016-12-06
- 0.0.4 — 2016-12-06
- 0.0.3 — 2016-12-06
- 0.0.2 — 2016-12-05

## README

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

	}

---
_Source: https://npm.io/package/micromachine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
