fastify-hemera
fastify-hemera
npm i fastify-hemera
fastify-hemera

fastify-hemera

Fastify plugin to integrate Hemera

by hemerajs

10.0.0 (see all)License:ISCTypeScript:Not Found
npm i fastify-hemera
Readme

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

Downloads/wk

20

GitHub Stars

10

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

1

OPEN ISSUES

1

OPEN PRs

11
VersionTagPublished
10.0.0
latest
2yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate