Skip to content

nano2 service actions(functions) framework, supports middleware and plugins.

License

Notifications You must be signed in to change notification settings

mailaneel/nano2

Repository files navigation

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).

About

nano2 service actions(functions) framework, supports middleware and plugins.

Resources

License

Stars

Watchers

Forks

Packages

No packages published