liveBook · Manning

Grpcurl

As explained in Learn Go with Pocket-Sized Projects

grpcurl is a command-line tool for interacting with gRPC services similarly to how curl interacts with HTTP services.

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

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains installation, Protobuf inputs, request formatting, reflection avoidance, and multi-step endpoint use, but not grpcurl internals.
Examples
Demonstrates habit creation, listing, ticking, timestamped ticking, and status retrieval through terminal commands.
What it assumes
Assumes a running gRPC server and available `.proto` definitions while teaching installation and command construction.
What you can do after
Diagnose/debug with it by manually sending Protobuf-backed requests and inspecting gRPC responses.
How it connects
Connects gRPC, curl, Protocol Buffers, `.proto` files, reflection, and RPC status codes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.