0.0.11 • Published 6 years ago

nano2 v0.0.11

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Install

nano2 requires node v8.0.0 or higher

$ npm install nano2

Usage

Create Service

import nano2 from 'nano2';

// create service
const service = nano2();

Middleware

Middleware works same as koa js middleware and internally it uses koa-compose

service.use((ctx, next) => {
  ctx.meta.user = {
    name: 'user',
  };
  return next();
});

Actions

// add ping action
service.action('ping', () => 'pong');

// add math.add action
service.action('math.add', ctx => ctx.params.a + ctx.params.b);

// add math.multiply using action spec
service.action({
  name: 'math.multiply',
  version: '1.0',
  description: 'Math multiplication',
  type: 'service',
  handler: ctx => ctx.params.a * ctx.params.b;
});

Start

await service.start()

Run

// call ping action
const pingResponse  = await service.call('ping');

// call math.add action
const addResponse = await service.call('math.add', { a: 5, b: 3 });

// call math.multiply action
const multiplyResponse = await service.call('math.multiply', { a: 5, b: 3 });

Plugins

TODO

Types

Please see types.ts

Inspiration

License

See the LICENSE file for license rights and limitations (MIT).

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 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