10.0.0 • Published 4 years ago

fastify-hemera v10.0.0

Weekly downloads
46
License
ISC
Repository
github
Last release
4 years ago

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
10.0.0

4 years ago

9.0.0

5 years ago

7.2.3

6 years ago

7.2.2

6 years ago

7.2.1

6 years ago

7.2.0

6 years ago

7.1.0

6 years ago

7.0.0

6 years ago

6.0.0

6 years ago

5.0.0

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago

0.0.1

7 years ago

1.0.1

7 years ago