Fastify plugin to integrate Hemera
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.eslintignore
.eslintrc.json
.gitignore
.prettierignore
.prettierrc
.travis.yml
LICENSE
README.md
basic.test.js
docker-compose.yml
example.js
index.js
package-lock.json
package.json
plugin.test.js

README.md

fastify-hemera

Build Status styled with prettier NPM version

Fastify plugin to integrate Hemera

Install

npm install --save fastify-hemera

Register plugin

fastify.register(require('fastify-hemera'), {
  plugins: [require('hemera-mongo-store')],
  hemera: {
    name: 'test',
    logLevel: 'debug'
  },
  nats: 'nats://localhost:4242'
})

Full list of hemera plugins

Getting Started

$ docker-compose up
$ node example.js
$ curl http://localhost:3000/reply?a=33&b=22

Examples

Simple

fastify.route({
  method: 'GET',
  url: '/math/add',
  handler: (req, reply) => {
    reply.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
  }
})

Async / Await

fastify.route({
  method: 'GET',
  url: '/math/add',
  handler: async function (req, reply) {
    let resp = await req.hemera.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
    // access result
    resp.data
    // retain parent context
    resp = resp.context.act(...)
  }
})