How to curl a POST endpoint with a protobuf payload
Asked Answered
J

2

6

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.

Jocularity answered 30/7, 2020 at 20:23 Comment(0)
P
3

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.)

Pyrrhonism answered 29/4, 2022 at 11:55 Comment(1)
Wonderful tool!Addi
L
0

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
Ledoux answered 3/4, 2024 at 18:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.