Skip to content

Instantly share code, notes, and snippets.

@alexeypegov
Last active April 27, 2022 23:36
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save alexeypegov/7887216 to your computer and use it in GitHub Desktop.
Save alexeypegov/7887216 to your computer and use it in GitHub Desktop.
ProtoBuffers debug with CURL. ProtoBuffers should be installed first: "yum install protobuf" or "brew install protobuf".
key:"string value"
int_key:22
#!/bin/bash
URL=full_method_url # i.e. "http://server.com/my/method" (without quotes)
REQUEST=request_message_name # i.e. "Request"
RESPONSE=response_message_name # i.e. "Response"
PROTO=proto_file_name # i.e. "./Protocol.proto"
cat proto.msg | protoc --encode $REQUEST $PROTO | curl -sS -X POST --data-binary @- $URL | protoc --decode $RESPONSE $PROTO
@abhivaikar
Copy link

How do we construct complex request messages with this approach?

@GollyTicker
Copy link

GollyTicker commented Apr 27, 2022

There is protocurl - a command line tool specifically created for this purpose of debugging Protobuf endpoints similar to cURL + JSON.

A request would look like this:

protocurl -I path/to/protos -i ..MyRequest -o ..MyResponse \
  -u <URL> -d 'key: "string", int_key: 42'

It also works with JSON input/output and the text format is documented on the README.

(Disclaimer: I am the author of this CLI since I had the same problem and needed a better tool.)

@abhivaikar
Copy link

This is amazing. Thanks for sharing @GollyTicker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment