grpc2http
v0.1.6
Published
A grpc api to http api tool
Downloads
7
Readme
A grpc api to http api tool
接受http请求转换成grpc请求并转发到grpc服务, 支持热重载proto文件
http client => [ http server -> grpc client ] => grpc Server
Features
- 支持热重载proto文件
- 支持url query参数和post json参数合并,并映射到grpc参数
- 支持http header映射到grpc medadata
- proto文件支持import
- 支持Web Debugger
Default grpc config
'grpc.max_send_message_length': 128*1024*1024,
'grpc.max_receive_message_length': 128*1024*1024,
Install
npm -g i grpc2http
How To Use
> grpc2http -h
Usage: grpc2http [options]
http client => [ http server -> grpc client ] => grpc Server
Options:
-v, --version output the current version
-i, --input [input] protos directory
-g, --grpchost [grpchost] grpc server host (ip:port)
-p, --httpport [httpport] local http listen port
-o, --oneofs [oneofs] set proto oneofs config as true
-e, --enums [enums] set proto enums config: String | Number
-c, --config [config] config file (default name is grpc2http.config.json)
-h, --help display help for command
Use config file
add grpc2http.config.json in project root direction
add follow json to file:
{
"grpcHost": "127.0.0.1:9503",
"httpPort": "3503",
"protoPath": "grpc/protos",
}
sample proto file
// protos/sample.proto
syntax = "proto3";
package mycom.sample;
service User {
rpc getInfo (GetUserInfoRequest) returns(GetUserInfoResponse) {}
}
message UserInfo {
int32 userId = 1;
string name = 2;
string title = 3;
int32 age = 4;
}
message GetUserInfoRequest {
int32 userId = 1;
}
message GetUserInfoResponse {
int32 code = 1;
string msg = 2;
UserInfo data = 3;
}
> http2grpc -i protos/
grpc server host: 127.0.0.1:9503
http listen port: 3503
{
"mycom.sample": {
"User": [
"getInfo"
]
}
}
grpc methods list:
/mycom.sample.User/getInfo
Now you can open it from browser:
127.0.0.1:3503/mycom.sample.User/getInfo/?userId=123