grpcurl is a command-line tool for communicating with gRPC servers, much as curl communicates with HTTP services. It is useful for manually testing endpoints without first building a client application. section 10.3.2 section 10.8
A typical grpcurl session follows these steps:
- Start the gRPC server, then install the CLI with `go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest`. section 10.3.2
- Pass the relevant `.proto` file with `-proto` and provide its import root with `-import-path`, allowing grpcurl to understand service and message definitions. section 10.3.2
- Send a JSON-shaped request with `-d`, while targeting the server address and fully qualified RPC method. section 10.3.2 section 10.8
- Use supplied `.proto` definitions instead of reflection when reflection overhead is undesirable for production servers. section 10.3.2
Create a habit
grpcurl -import-path api/proto/ -proto service.proto -plaintext -d '{"name":"Write some Go code", "weekly_frequency":3}' localhost:28710 habits.Habits/CreateHabit The response contains the created habit and its generated identifier. That identifier can then be supplied to TickHabit and GetHabitStatus requests. section 10.7.6
> grpcurl \
-import-path /.../learngo-pockets/habits/api/proto/ \ #1
-proto service.proto \ #2
-plaintext -d '{"name":"clean the kitchen"}' \ #3
localhost:28710 \ #4
habits.Habits/CreateHabit #5
Browse the complete command structure for installing grpcurl and invoking CreateHabit with a local server, Protobuf definition, plaintext transport, and request data. section 10.3.2
> grpcurl \
-import-path api/proto/ \
-proto service.proto \
-plaintext -d '{"name":"Write some Go code", "weekly_frequency":3}' \
localhost:28710 \
habits.Habits/CreateHabit
Browse a concrete habit-tracker request that supplies a name and weekly frequency to CreateHabit. section 10.7.6
