如何使用Protobuf负载来进行POST端点的curl请求。

huangapple go评论87阅读模式
英文:

How to curl a POST endpoint with a protobuf payload

问题

我有一个Java服务中的POST端点,它期望一个Protobuf 3负载。其他服务使用这个服务发送Protobuf负载。我想要做一些调试,并通过curl命令发送一个Protobuf负载到该服务,然而,我不知道如何构造这样的负载,因为它是一个二进制协议。

英文:

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.

答案1

得分: 2

你可以使用 protoCURL 来实现这个目的。它是一个命令行工具,用于发送和接收 Protobuf HTTP REST 请求,同时将它们编写成 Protobuf TextJSON 格式。

一个请求可能看起来像这样:

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

响应可能如下所示:

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

你可以在 repository 中找到更多使用示例。

(免责声明:我是这个工具的作者,因为我遇到了相同的问题并需要一个更好的工具才创建了它。)

英文:

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

huangapple
  • 本文由 发表于 2020年7月31日 04:23:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63180847.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定