0.1.31 • Published 2 years ago

grpc-mocky v0.1.31

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

Introduction

  • This is a mock of grpc used for javascript development
  • Can have multiple entry points
  • Supports the following methods
    • unary
    • serverStreming
    • clientStreming
    • duplexStreming

Install

npm i -D grpc-mocky

Cli

gen-grpc-tamplate

  • Output mock json template
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-mocky/blob/master/example/service.json https://github.com/activeguild/grpc-mocky#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-mocky#user-content-service

service

ParameterTypeDescription
namestringRequired. Set service name from ptoro file.
methodsArray\<method>Required. https://github.com/activeguild/grpc-mocky#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-mocky/tree/master/example

License

0.1.31

2 years ago

0.1.30

2 years ago

0.1.29

2 years ago

0.1.27

3 years ago

0.1.26

3 years ago

0.1.24

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.21

3 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.16

4 years ago

0.1.17

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago