【问题标题】:How does one send a REST request to an annotated GRPC endpoint?如何向带注释的 GRPC 端点发送 REST 请求?
【发布时间】:2019-09-28 22:15:09
【问题描述】:

curling GRPC protobuf 中的 REST 注释端点时,我没有收到有效响应

我目前正在从here 运行bookstore server

我已经能够使用提供的客户端通过 GRPC 成功访问端点。

$ python bookstore_client.py
ListShelves: shelves {
  id: 1
  theme: "Fiction"
}
shelves {
  id: 2
  theme: "Fantasy"
}

当我尝试点击相应的 REST 端点时,它会返回一个非文本(即非 JSON)响应

$ curl --raw --http2 localhost:8000/v1/shelves 2>/dev/null | xxd
00000000: 0000 1804 0000 0000 0000 0400 4000 0000  ............@...
00000010: 0500 4000 0000 0600 0020 00fe 0300 0000  ..@...... ......
00000020: 0100 0004 0800 0000 0000 003f 0001 0000  ...........?....
00000030: 0806 0000 0000 0000 0000 0000 0000 00    ...............

无论 uri 是什么,我都会收到此响应,即/v1/foobar 给出相同的结果

这是来自protobuf的相关行

  rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) {
    // Define HTTP mapping.
    // Client example (Assuming your service is hosted at the given 'DOMAIN_NAME'):
    //   curl http://DOMAIN_NAME/v1/shelves
    option (google.api.http) = { get: "/v1/shelves" };
  }

我希望得到与 python 客户端相同的响应,但我收到了来自 GRPC 服务器的非文本响应。

【问题讨论】:

    标签: rest grpc http2


    【解决方案1】:

    在该示例中,端口 8000 是 gRPC,而不是 REST 端点。

    要运行遵循注释的端点,您需要从 docs 运行可扩展服务代理:

    “Cloud Endpoints 支持协议转码,以便客户端可以使用 HTTP/JSON 访问您的 gRPC API。可扩展服务代理 (ESP) 将 HTTP/JSON 转码为 gRPC。”

    REST 端点将通过 ESP --http_port 选项在不同的端口上提供服务。

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      相关资源
      最近更新 更多