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

grpc-mock

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-mock

a simple grpc mock server

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

grpc-mock

npm version

A simple mock gRPC server on Node.js.

const {createMockServer} = require("grpc-mock");
const mockServer = createMockServer({
  protoPath: "/path/to/greeter.proto",
  packageName: "greeter",
  serviceName: "Greeter",
  rules: [
    { method: "hello", input: { message: "test" }, output: { message: "Hello" } },
    { method: "goodbye", input: ".*", output: { message: "Goodbye" } },
    
    {
      method: "howAreYou",
      streamType: "client",
      stream: [
        { input: { message: "Hi" } },
        { input: { message: "How are you?" } },
      ],
      output: { message: "I'm fine, thank you" }
    },
    
    {
      method: "niceToMeetYou",
      streamType: "server",
      stream: [
        { output: { message: "Hi, I'm Sana" } },
        { output: { message: "Nice to meet you too" } },
      ],
      input: { message: "Hi. I'm John. Nice to meet you" }
    },
    
    {
      method: "chat",
      streamType: "mutual",
      stream: [
        { input: { message: "Hi" }, output: { message: "Hi there" } },
        { input: { message: "How are you?" }, output: { message: "I'm fine, thank you." } },
      ]
    },
    
    { method: "returnsError", input: { }, error: { code: 3, message: "Message text is required"} },
    
    {
      method: "returnsErrorWithMetadata",
      streamType: "server",
      input: { },
      error: { code: 3, message: "Message text is required", metadata: { key: "value"}}
    }
  ]
});
mockServer.listen("0.0.0.0:50051");
syntax="proto3";

package greeter;

service Greeter {
  rpc Hello (RequestGreet) returns (ResponseGreet) {}
  rpc Goodbye (RequestGreet) returns (ResponseGreet) {}
  rpc HowAreYou (stream RequestGreet) returns (ResponseGreet) {}
  rpc NiceToMeetYou (RequestGreet) returns (stream ResponseGreet) {}
  rpc Chat (stream RequestGreet) returns (stream ResponseGreet) {}
}

message RequestGreet {
  string message = 1;
}

message ResponseGreet {
  string message = 1;
}

api

createMockServer({protoPath,packageName,serviceName,options,rules}): grpc-kit.GrpcServer

arg nametyperequired/optionaldescription
protoPathStringRequiredpath to .proto file
packageNameStringRequiredname of package
serviceNameStringRequiredname of service
options@grpc/proto-loader.OptionsOptionaloptions for @grpc/proto-loader to load .proto file. In detail, please check here out. Default is null
rulesArray<Rule>RequiredArray of Rules

Rule

prop nametyperequired/optionaldescription
methodStringRequiredpath to .proto file
streamTypeEnum<"client"|"server"|"mutual">OptionalType of stream. Set client if only using client side stream, set server if only using server side stream, and set mutual if using both of client and server side stream. Set null/undefined if not using stream. Default is null
inputObject|StringRequired when streamType is null or serverSpecifying an expected input. Raw object or pattern string(RegExp) is available
outputStringRequired when streamType is null or clientSpecifying an output to an expected input
streamArray<Chunk>Required when streamType is client, server and mutualArray of Chunks
errorObjectOptionalIf provided, server will respond with this error object
Chunk
prop nametyperequired/optionaldescription
inputObject|StringRequired when streamType is client. Optional when streamType is mutualSpecifying an expected input. Raw object or pattern string(RegExp) is available.
outputObjectRequired when streamType is server. Optional when streamType is mutualSpecifying an output to an expected input

Keywords

FAQs

Package last updated on 10 Jul 2019

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