Basic tutorial into setting up a gRPC reverse proxy that will transform REST JSON into gRPC, along with instructions on how to generate Swagger definitions. Instructions on how to run client/server in other languages.
- service defintion in
service.proto
- generate client and server code using
protoc
. - wrap generated code to expose light client (and server).
- generate gateway code for HTTP/JSON reverse proxy.
- get Swagger UI to render service's Swagger JSON (with auth)
- auth definitions in proto
- investigate python reverse proxy support #398
- write up instructions for java {grpc-jersey}
- find a contributor for nodejs
- use
gvm
or something to get Go >= 1.6 brew install protobuf
orapt install libprotobuf-dev
$ go help gopath # make sure GOPATH is set
go get google.golang.org/grpc
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
This is the basic architecture of a grpc-gateway application {from grpc-ecosystem/grpc-gateway/
}.
To generate:
$ protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=google/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
pb/service.proto
To generate:
$ protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
pb/service.proto
go run server/server.go
...
go run client/client.go
Will display 2018/05/28 12:57:11 Hello debo!
go run server/server.go
...
go run server/server-rproxy.go
...
curl -X POST "http://localhost:8080/v1/example/hello/v1/world" | jq .
Will display
{
"id": "v1",
"msg": "world"
}
PR to update gRPC docs: #671
pb/service_pb2.py
pb/service_pb2_grpc.py
To generate:
virtualenv env
. env/bin/activate
pip install grpcio-tools googleapis-common-protos
python -m grpc_tools.protoc --python_out=. \
--grpc_python_out=. -I. -I/usr/local/include \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
-I/usr/local/include \
pb/service.proto
python -m server.server
...
python -m client.client
Will display Hello world!
I don't believe this can be done in the state of the world at the time of writing.
To generate:
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:. \
pb/service.proto