Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hemerajs/fastify-hemera
Fastify plugin to integrate Hemera
https://github.com/hemerajs/fastify-hemera
api-gateway fastify fastifyjs-plugin hemera
Last synced: about 2 months ago
JSON representation
Fastify plugin to integrate Hemera
- Host: GitHub
- URL: https://github.com/hemerajs/fastify-hemera
- Owner: hemerajs
- License: mit
- Created: 2017-09-23T10:44:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T13:28:56.000Z (about 2 years ago)
- Last Synced: 2024-04-14T05:40:33.239Z (9 months ago)
- Topics: api-gateway, fastify, fastifyjs-plugin, hemera
- Language: JavaScript
- Size: 678 KB
- Stars: 12
- Watchers: 5
- Forks: 1
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastify - `fastify-hemera` - tolerant microservices with [nats.io](https://nats.io/). (<h2 align="center">Awesome Fastify</h2> / <h2 align="center">Ecosystem</h2>)
README
# fastify-hemera
[![Build Status](https://travis-ci.org/hemerajs/fastify-hemera.svg?branch=master)](https://travis-ci.org/hemerajs/fastify-hemera)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](#badge)
[![NPM version](https://img.shields.io/npm/v/fastify-hemera.svg?style=flat)](https://www.npmjs.com/package/fastify-hemera)[Fastify](https://github.com/fastify/fastify) plugin to integrate [Hemera](https://github.com/hemerajs/hemera)
## Install
```bash
npm install --save fastify-hemera
```## Register plugin
```js
fastify.register(require('fastify-hemera'), {
plugins: [require('hemera-mongo-store')],
hemera: {
name: 'test',
logLevel: 'debug'
},
nats: 'nats://localhost:4242'
})
```Full list of [hemera plugins](https://github.com/hemerajs/hemera#packages)
## Getting Started
```bash
$ docker-compose up
$ node example.js
$ curl http://localhost:3000/reply?a=33&b=22
```## Examples
Simple
```js
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
```js
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](https://github.com/hemerajs/hemera-testsuite), so your setup should meet it's prerequisits, esp.:
A nats server must be installed on your machine [nats.io](https://nats.io/download/nats-io/nats-server/) and executable as `gnatsd`. So add `nats-server` as `gnatsd` to your `PATH` as alias, link whatever works. Check if it's available:
```sh
$ gnatsd --helpUsage: nats-server [options]
[...]
```Now test should succeed by running:
```sh
$ yarn test
```