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.

Screenshot 2020 10 30 at 15.40.41 1024x53 - GRPCURL

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

Screenshot 2020 10 30 at 15.52.51 1024x83 - GRPCURL

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

Screenshot 2020 10 30 at 15.53.31 1024x151 - GRPCURL

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

Screenshot 2020 10 30 at 15.53.52 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.

Screenshot 2020 10 30 at 15.50.04 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!