Thiago's Space Blog

Just another blog, this one about my learnings as I join the Space Industry as a software engineer.

View on GitHub
11 January 2022

Grpcurl

grpcurl and gRPC Reflection

I just found out about grpcurl and I’m already in love. As the README says, it’s basically curl for gRPC servers. Here’s how to use it to invoke the gRPC service in our example code:

> grpcurl \
    --plaintext \
    -d '{"message": "greetings grpcurl"}' \
    localhost:8080 \
    grpc_example_proto.Unary/GetServerResponse
     
{
  "message": "Hello I am up and running received \"greetings grpcurl\" message from you",                                                                                    
  "received": true
}

In command above, method grpc_example_proto.Unary/GetServerResponse in server running at localhost:8080 is invoked with '{"message": "greetings grpcurl"}'. Flag plaintext is required to use plain-text HTTP/2 when connecting to server, instead of TLS.

If the server supports gRPC Reflection, you can use list to list all exposed services or methods of a particular service:

> grpcurl --plaintext localhost:8080 list

grpc.reflection.v1alpha.ServerReflection
grpc_example_proto.Unary

> grpcurl --plaintext localhost:8080 list grpc_example_proto.Unary

grpc_example_proto.Unary.GetServerResponse

You can also use describe to learn more about exposed services:

> grpcurl --plaintext localhost:8080 describe

grpc.reflection.v1alpha.ServerReflection is a service:
service ServerReflection {
  rpc ServerReflectionInfo ( stream .grpc.reflection.v1alpha.ServerReflectionRequest ) returns ( stream .grpc.reflection.v1alpha.ServerReflectionResponse );
}
grpc_example_proto.Unary is a service:
service Unary {
  rpc GetServerResponse ( .grpc_example_proto.Message ) returns ( .grpc_example_proto.MessageResponse ) {
    option (.google.api.http) = { post:"/v1/response" body:"*"  };
  }
}

I just committed a change to enable gRPC Reflection in our example code: f5c842e (docs).