'How to curl a POST endpoint with a protobuf payload

I have a POST endpoint in my Java service that expects a protobuf 3 payload. This service is used by other services which send the protobuf payload. I would like to do some debugging and send a protobuf payload to the service via a curl command, however, I have no idea how to construct such a payload, given it's a binary protocol.



Solution 1:[1]

You can use protoCURL for this purpose. It's a command-line tool to send and receive protobuf HTTP REST requests while writing them in the Protobuf Text or JSON format.

A request could look something like this:

protocurl -I path/to/protos -i ..MyRequest -o ..MyResponse \
  -u http://host/path/o/endpoint -d 'someField: "some-string", someIntField: 42'

And the response may look like this:

=========================== Request Text     =========================== >>>
someField: "my-string"
someIntField: 42
=========================== Response Text    =========================== <<<
someResponseField: "The answer for everything!"
someOtherResonseMessage: {
  fooEnum: BAR
}

You can find more examples for how to use it in the repository.

(Disclaimer: I am the author of this tool and created it, because I had the same problem and needed a better tool.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Golly Ticker