0.1.32 • Published 2 years ago

grpc-json-mock v0.1.32

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Introduction

  • A GRPC mock server for front-end development.
  • Multiple APIs are supported.
  • Supports the following APIs
    • unary
    • serverStreming
    • clientStreming
    • duplexStreming

Install

npm i -D grpc-json-mock

Cli

gen-grpc-tamplate

  • By specifying a proto file, you can output a json template for use in mock.
node ./node_module/.bin/gen-grpc-template {path}
ParameterDescription
pathSet the directory where the proto file or proto file is located
  • option
optionDescription
-iimport another path
  • e.g.
syntax = "proto3";
package helloworld;

service Greeter {
  rpc unary (UnaryRequest) returns (UnaryResponse) {}
  rpc serverStreaming (UnaryRequest) returns (stream UnaryResponse) {}
  rpc clientStreaming (stream UnaryRequest) returns (UnaryResponse) {}
  rpc duplexStreaming (stream UnaryRequest) returns (stream UnaryResponse) {}
}

message UnaryRequest {
  string name = 1;
}

message UnaryResponse {
  string message = 1;
}

generate...

{
  "protos": [
    {
      "path": "example/protos/helloWorld.proto",
      "pkg": "helloworld",
      "options": {},
      "services": [
        {
          "name": "Greeter",
          "methods": [
            { "name": "unary", "output": {} },
            { "name": "serverStreaming", "output": {} },
            { "name": "clientStreaming", "output": {} },
            { "name": "duplexStreaming", "output": {} }
          ]
        }
      ]
    }
  ]
}

Interface

run

ParameterTypeDescription
addressstringSet the address of the mock server to be started. default 0.0.0.0
portstringSet the port of the mock server to be started. default 50051
protosArray\<proto>Required. Set proto and mock data to be loaded into mock server. e.g. https://github.com/activeguild/grpc-json-mock/blob/master/example/service.json https://github.com/activeguild/grpc-json-mock#user-content-proto

proto

ParameterTypeDescription
pathstringRequired. Set location of proto file.
pkgstringRequired. Set pkgName from ptoro file.
optionsstringhttps://github.com/grpc/grpc-node/tree/master/packages/proto-loader
servicesArray\<service>Required. https://github.com/activeguild/grpc-json-mock#user-content-service

service

ParameterTypeDescription
namestringRequired. Set service name from ptoro file.
methodsArray\<method>Required. https://github.com/activeguild/grpc-json-mock#user-content-method

method

ParameterTypeDescription
namestringRequired. Set method name from ptoro file.
outputObject | Array\<object>Set response from server.
streamIntervalnumberSet the sense of server streaming.Unit is msec. default 1000
errorObjectSet grpc error. https://cloud.google.com/apis/design/errors#error_model

e.g.

https://github.com/activeguild/grpc-json-mock/tree/master/example

License