fastify-hemera

10.0.0 • Public • Published

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

Test

Testsuite makes use of hemera-testsuite, so your setup should meet it's prerequisits, esp.:

A nats server must be installed on your machine nats.io and executable as gnatsd. So add nats-server as gnatsd to your PATH as alias, link whatever works. Check if it's available:

$ gnatsd --help
 
Usage: nats-server [options]
 
[...]

Now test should succeed by running:

$ yarn test

Package Sidebar

Install

npm i fastify-hemera

Weekly Downloads

6

Version

10.0.0

License

ISC

Unpacked Size

11.7 kB

Total Files

19

Last publish

Collaborators

  • starptech