⚠️ Status: ExperimentalThis project is currently in a highly experimental phase. It is a working prototype intended for testing and development purposes. APIs, command-line arguments, and internal logic are subject to breaking changes. Please use with caution.
Granc (gRPC + Cranc, Crab in Catalan) is a lightweight, dynamic gRPC CLI tool written in Rust.
It allows you to make gRPC calls to any server using simple JSON payloads, without needing to compile the specific Protobuf files into the client. By loading a FileDescriptorSet at runtime, granc acts as a bridge between human-readable JSON and binary Protobuf wire format.
It is heavily inspired by tools like grpcurl but built to leverage the safety and performance of the Rust ecosystem (Tonic + Prost).
- Dynamic Encoding/Decoding: Transcodes JSON to Protobuf (and vice versa) on the fly using
prost-reflect. - Smart Dispatch: Automatically detects if a call is Unary, Server Streaming, Client Streaming, or Bidirectional based on the descriptor.
- Server Reflection: Can fetch schemas directly from the server, removing the need to pass a local file descriptor set file (
.binor.pb). - Metadata Support: Easily attach custom headers (authorization, tracing) to your requests.
- Fast Fail Validation: Validates your JSON before hitting the network.
- Zero Compilation Dependencies: Does not require generating Rust code for your protos. Just point to a descriptor file.
- Tonic 0.14: Built on the latest stable Rust gRPC stack.
cargo install grancEnsure you have Rust and Cargo installed.
git clone https://github.com/JasterV/granc
cd granc
cargo install --path .Granc needs to know the schema of the service you are calling. It can obtain this in two ways:
- Automatic Server Reflection: If the server has Server Reflection enabled, Granc can download the schema automatically.
- Local Descriptor File: You can provide a binary
FileDescriptorSet(.bin) generated byprotoc.
If your server does not support reflection, you must generate a descriptor file:
# Generate descriptor.bin including all imports
protoc \
--include_imports \
--descriptor_set_out=descriptor.bin \
--proto_path=. \
my_service.protoNote: The
--include_importsflag is crucial. It ensures that types defined in imported files (likegoogle/protobuf/timestamp.proto) are available for reflection.
Syntax:
granc [OPTIONS] <URL> <ENDPOINT>| Argument | Description | Required |
|---|---|---|
<URL> |
Server address (e.g., http://[::1]:50051). |
Yes |
<ENDPOINT> |
Fully qualified method name (e.g., my.package.Service/Method). |
Yes |
| Flag | Short | Description | Required |
|---|---|---|---|
--proto-set |
Path to the binary FileDescriptorSet (.bin). |
No | |
--body |
The request body in JSON format. | Yes | |
--header |
-H |
Custom header key:value. Can be used multiple times. |
No |
If you omit the --proto-set flag, Granc will automatically attempt to connect to the server's reflection service to download the necessary schemas.
# Using Reflection (no descriptor file needed)
granc \
--body '{"name": "Ferris"}' \
http://localhost:50051 \
helloworld.Greeter/SayHelloThis requires the server to have the grpc.reflection.v1 service enabled.
- Unary / Server Streaming: Provide a single JSON object
{ ... }. - Client / Bidirectional Streaming: Provide a JSON array of objects
[ { ... }, { ... } ].
1. Unary Call (using local descriptor)
granc \
--proto-set ./descriptor.bin \
--body '{"name": "Ferris"}' \
http://localhost:50051 \
helloworld.Greeter/SayHello2. Bidirectional Streaming (Chat)
granc \
--body '[{"text": "Hello"}, {"text": "How are you?"}]' \
-H "authorization: Bearer token123" \
http://localhost:50051 \
chat.ChatService/StreamMessages- Interactive Mode: A REPL for streaming requests interactively.
- Pretty Printing: Enhanced colored output for JSON responses.
- TLS Support: Configurable root certificates and client identity.
**1. Service 'x' not found**
- Cause: The service name in the command does not match the package defined in your proto file.
- Fix: Check your
.protofile. If it haspackage my.app;andservice API {}, the full name ismy.app.API.
**2. Method 'y' not found in service 'x'**
- Cause: Typo in the method name or the method doesn't exist.
- Fix: Ensure case sensitivity matches (e.g.,
GetUservsgetUser).
**3. h2 protocol error**
- Cause: This often occurs when the JSON payload fails to encode after the connection has already been established, or the server rejected the stream structure.
- Fix: Double-check your JSON payload against the Protobuf schema.
Contributions are welcome! Please run the Makefile checks before submitting a PR:
cargo make ci # Checks formatting, lints, and runs testsLicensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.