如何向带注释的 GRPC 端点发送 REST 请求?

How does one send a REST request to an annotated GRPC endpoint?

curl从 GRPC protobuf

ing REST 注释端点时,我没有收到有效响应

我目前 运行 bookstore server from here

我已经能够使用提供的客户端通过 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 服务器的非文本响应。

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

到 运行 注释后的端点 运行 可扩展服务代理,来自 docs:

"Cloud Endpoints supports protocol transcoding so that clients can access your gRPC API by using HTTP/JSON. The Extensible Service Proxy (ESP) transcodes HTTP/JSON to gRPC."

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