fastify-grpc-client

GRPC client plugin for Fastify

Usage no npm install needed!

<script type="module">
  import fastifyGrpcClient from 'https://cdn.skypack.dev/fastify-grpc-client';
</script>

README

fastify-grpc-client

Package Version Dependency Status Build

GRPC client plugin for Fastify

Install

Just run:

npm install fastify-grpc-client --save

Test

Clone this repository, then do:

npm install
npm test

Usage

Register as a plugin:

const grpcClient = require('fastify-grpc-client');
...
fastify.register(grpcClient, {
  protoFile: path.join(__dirname, 'your_proto_file.proto'),
  server: 'localhost',
  port: 50051,
  namespace: 'helloworld',
  service: 'NameOfService'
});

You can then use your gRPC services as follows:

fastify.get('/echo', function (request, reply) {
  const msg = request.query.msg;
  this.grpc.helloworld.invoke('Greet', {
    greeting: {
      first_name: msg,
      last_name: 'boh'
    }
  }, (err, response) => {
      return reply.send(response.result);
  })
})

Adding multiple clients is supported, each one will have its separate namespace.

Contributing

See CONTRIBUTING.md

License

Copyright NearForm Ltd 2019. Licensed under the Apache-2.0 license.