Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@grpc.ts/core

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grpc.ts/core

Core package for @grpc.ts

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
82
increased by38.98%
Maintainers
1
Weekly downloads
 
Created
Source

A wrapper of @grpc/grpc-js for Node.JS.

Install

npm install --save @grpc.ts/core

# or

yarn add @grpc.ts/core

# or

pnpm add @grpc.ts/core

Usage

Define proto file

// 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);
}

Client Usage

import { createClient } from '@grpc.ts/core';

async function main(): Promise<void> {
  const client = await createClient({
    url: 'localhost:3010',
    package: [
      {
        packageName: 'example.v1',
        protoPath: '../proto/example.proto',
      },
    ],
    packageDefinitionOptions: {
      oneofs: true,
      longs: String,
      enums: String,
      defaults: true,
    },
    options: {
      keepaliveTimeMs: 5_000,
    },
  });

  client.getService('ExampleService').sendMessage(
    { message: 'hello', createdAt: dateToGrpcTimestamp(new Date()) },
    createMetadata({
      meta: 'test',
    }),
  );
}

main();

Server Usage

import { createServer, dateToGrpcTimestamp } from '@grpc.ts/core';

async function main(): Promise<void> {
  const serverObj = await createServer({
    url: 'localhost:3010',
    package: [
      {
        packageName: 'example.v1',
        protoPath: '../proto/example.proto',
      },
    ],
    packageDefinitionOptions: {
      oneofs: true,
      longs: String,
      enums: String,
      defaults: true,
    },
    options: {
      keepaliveTimeMs: 5_000,
    },
  });

  serverObj.addUnaryHandler(
    'ExampleService',
    'sendMessage',
    (request, metadata) => {
      console.log(request);
      console.log(metadata);
      return {
        message: {
          message: 'hola',
          createdAt: dateToGrpcTimestamp(new Date()),
        },
      };
    },
  );
}

main();

TODO

  • Support Server Streaming Call
  • Support Client Streaming Call
  • Support Bidi Streaming Call

Keywords

FAQs

Package last updated on 16 Apr 2023

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