New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@grpc.ts/fastify-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grpc.ts/fastify-client

Fastify package for client

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Fastify's Plugin for gRPC Client.

Install

npm install --save @grpc.ts/fastify-client

# or

yarn add @grpc.ts/fastify-client

# or

pnpm add @grpc.ts/fastify-client

Usage

// example.proto

syntax = "proto3";

import "google/protobuf/timestamp.proto";

package example.v1;

message Message {
  string message = 1;
  google.protobuf.Timestamp created_at = 2;
}

message SendMessageRequest {
  string message = 1;
  google.protobuf.Timestamp created_at = 2;
}

message GetMessageResponse { Message message = 1; }

service ExampleService {
  rpc SendMessage(SendMessageRequest) returns (GetMessageResponse);
}

In fastify

import Fastify from 'fastify';
import detect from 'detect-port';
import FastifyGrpcClient, { createMetadata } from '@grpc.ts/fastify-client';

const fastify = Fastify({
  logger: process.env.NODE_ENV === 'production' ? false : true,
});

async function bootstrap(): Promise<typeof fastify> {
  fastify.register(FastifyGrpcClient, {
    url: 'localhost:3010',
    package: [
      {
        packageName: 'example.v1',
        protoPath: '../proto/example.proto',
      },
      {
        packageName: 'example2.v1',
        protoPath: '../proto/example2.proto',
      },
      {
        protoPath: '../proto/example3.proto',
      },
    ],
    packageDefinitionOptions: {
      oneofs: true,
      longs: String,
      enums: String,
      defaults: true,
    },
    options: {
      keepaliveTimeMs: 5_000,
    },
  });

  const port = await detect(3_000);
  await fastify.listen({
    port,
  });

  const result = await fastify.grpcClient
    .getService('ExampleService')
    .sendMessage(
      { message: 'hello', createdAt: dateToGrpcTimestamp(new Date()) },
      createMetadata({
        meta: 'test',
      }),
    );

  console.log(result);

  return fastify;
}

bootstrap();

TODO

  • Support Client Streaming Call
  • Support Bidi Streaming Call

Keywords

FAQs

Package last updated on 10 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc