Hello gRPC-Web

What you know

What I did to know an overview of gRPC-Web is trying helloworld example and grpcurl on macbook.You can follow details in the offical repsository. I left some stuffs.

I learned

  • protocol buffers
  • gRPC Service with NodeJS
  • Envoy proxy
  • protobuf message classes
  • A static library easy to loaded by browser
  • Accessing gRPC service with grpcurl

I illustrate a diagram.

Easy gRPC web

What you should care if you use mac/windows

First, You remove --netwrok=host when you run envoy.

# without --network=host
$ docker run -d -p 8080:8080 -p 9901:9901 helloworld/envoy

Second, Use host.docker.internal as address of envoy yaml.

44
45
    # win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below
    hosts: [{ socket_address: { address: host.docker.internal, port_value: 9090 }}]

Result with developer console

You just open browser and developer console. You can see relusts.

Result with grpcurl

You should use 2 options which are -plaintext and -proto when you use grpc becuase this example does not provide TLS and server reflection. As you notice, -d is used to pass parameters.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ grpcurl -v -d '{"name": "bar"}' -plaintext -proto helloworld.proto localhost:8080 helloworld.Greeter/SayHello

Resolved method descriptor:
// unary call
rpc SayHello ( .helloworld.HelloRequest ) returns ( .helloworld.HelloReply );

Request metadata to send:
(empty)

Response headers received:
accept-encoding: identity,gzip
content-type: application/grpc
date: Mon, 09 Mar 2020 15:43:35 GMT
grpc-accept-encoding: identity,deflate,gzip
server: envoy
x-envoy-upstream-service-time: 4

Response contents:
{
  "message": "Hello! bar"
}

Response trailers received:
(empty)
Sent 1 request and received 1 response