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.
How to curl a POST endpoint with a protobuf payload
Asked Answered
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.)
Wonderful tool! –
Addi
I'd also use protocurl, but in case you have a file already encoded and want to use curl for HTTP POST request you can run it as:
curl -X POST -H "Content-Type: application/x-protobuf" --data-binary @encodedFileName http://localhost:8080/or-any-other-url-path
© 2022 - 2025 — McMap. All rights reserved.