This example demonstrates step by step to test grpc service using grpcurl
grpcurl is a command-line tool that lets you interact with gRPC servers. It's basically curl for gRPC servers.
The main purpose for this tool is to invoke RPC methods on a gRPC server from the command-line. gRPC servers use a binary encoding on the wire (protocol buffers, or "protobufs" for short). So they are basically impossible to interact with using regular curl (and older versions of curl that do not support HTTP/2 are of course non-starters).
Download grpcurl tool from https://github.com/fullstorydev/grpcurl/releases
See images attached below to see the responses of grpcurl requests
- create container
d container run -p 82:50051 samplegrpcservice -d
- list services
grpcurl localhost:50051 list
if you get error Failed to dial target host "localhost:50051": tls: first record does not look like a TLS handshake the either configure https certiticate for your grpc service or use -plaintext to ignore handshake error
grpcurl -plaintext localhost:50051 list
- list methods
grpcurl -plaintext localhost:50051 list Services.Calculator
- descibe method
grpcurl -plaintext localhost:50051 describe Services.Calculator.AddNumbers
- invoke method
grpcurl -plaintext -d '{"firstNumber":5,"secondNumber":3}' localhost:50051 Services.Calculator/AddNumbers
To see the step-by-step guide to deploy grpc service in aks. how to setup aks
- list services
grpcurl localhost:50051 list
if you get error Failed to dial target host "localhost:50051": tls: first record does not look like a TLS handshake the either configure https certiticate for your grpc service or use -plaintext to ignore handshake error
grpcurl -insecure localhost:50051 list
- list methods
grpcurl -insecure localhost:50051 list Services.Calculator
- descibe method
grpcurl -insecure localhost:50051 describe Services.Calculator.AddNumbers
- invoke method
grpcurl -insecure -d '{"firstNumber":5,"secondNumber":3}' localhost:50051 Services.Calculator/AddNumbers
Server Reflection error: If you are getting error: Failed to list services: server does not support the reflection API
then add in services folder. ReflectionImplementation
public class ReflectionImplementation : ReflectionServiceImpl
{
public ReflectionImplementation() : base(Calculator.Descriptor, Greeter.Descriptor, ServerReflection.Descriptor)
{
}
}
and in program.cs
endpoints.MapGrpcService<ReflectionImplementation>();
grpcurl https://github.com/fullstorydev/grpcurl