Are you looking for an easy way to test your gRPC endpoints? Use gRPCurl from the command line and see the result in Json. It’s basically curl for gRPC endpoints. In this post we will explore my method of exploratory testing a gRPC server.

The code and information on the tool is found on github here. More on gRPC reflection can be studied from here.

We will start with a project from a previous post on gRPC and micronaut. We add a reflection service and can test the API from the command line. The complete code can be found on github here.

Installation

On mac you can use homebrew to install.

brew install grpcurl

Reflection

gRPCurl uses gRPC reflection to make it work. Reflection is a service that is not present by default. We have to add it to the grpc server. The reflection service itself is in this dependency.

<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-services</artifactId>
</dependency>

Now we add it to the server builder on creation.

@Singleton
public class ServerBuilderListener implements BeanCreatedEventListener<ServerBuilder<?>> {
    
    @Override
    public ServerBuilder<?> onCreated(BeanCreatedEvent<ServerBuilder<?>> event) {
        final ServerBuilder<?> builder = event.getBean();
      builder.addService(ProtoReflectionService.newInstance());
        return builder;
    }
}

Testing

Let’s run the application and get started with exploring the API.

grpcurl list output 1024x53 - GRPCURL

Ok, we don’t expose the endpoint over https. Let’s try with http.

grpcurl list output underline 1024x83 - GRPCURL

Here we go. The reflection service is there and the CatService. I want to know more! We should use the describe method.

grpcurl describe output format 1024x151 - GRPCURL

Whow! We can get a cat. If only we would know what the request should look like…

grpcurl describe output terminal 1024x132 - GRPCURL

We are ready to call the gRPC endpoint. So leave out the list or describe keywords. And don’t forget the request in the -d section.

grpcurl request output cut 1024x153 - GRPCURL

And there is the response from the gRPC server.

Hopefully you are now able to explore and test your gRPC endpoints. Happy gRPCurling!