NevinJ
NevinJ

Reputation: 61

Cloud Endpoints support for proto3 Any type during JSON transcoding

We are exploring google Cloud Endpoints to expose gRPC services as REST APIs. These services use proto3 messages containing Any type fields.

Does Cloud Endpoints' Extensible Service Proxy (ESP) support JSON transcoding of Any fields embedding custom message types? Out of the box, it does not seem to support this and returns the following error

{
    "code": 13,
    "message": "Type 'type.acmeapis.com/acme.v1.Augmentation' cannot be found.",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.DebugInfo",
            "stackEntries": [],
            "detail": "internal"
        }
    ]
}

Would this require a TypeRegistry configured on the ESP and if so is there a way to do this?

Upvotes: 0

Views: 125

Answers (1)

DazWilkin
DazWilkin

Reputation: 40251

I've not tried using Cloud Endpoints with messages that include Any but I think it's unlikely that the proxy could be configured to transcode the enveloped message. It's possible but I think unlikely that even Envoy would enable this (but, again I don't know).

It's unclear what the semantics would be of the resulting REST API if this were to work:

rpc AddGeneric (AddGenericRequest) returns (AddGenericResponse) {}

Becomes, perhaps:

post: "v1alpha/add"
body: "generic"

Which using Any would be a type comprising an array of bytes and a string descriptor which is understandable as a REST API but, presumably the reason behind your question, requires the REST client to then decode the enveloped message.

But, if the transcoding were to recursively transcode enveloped messages, then this one (!) method would need to be defined with multiple possible message body types:

post: "v1alpha/add"
body: ["type-a" | "type-b" | "type-c" | ... ]

Which, while convenient seems a little un-RESTful. There's no requirement that transcoding produce RESTful APIs but it may explain the complexity involved.

To get a definitive response, I recommend you raise an issue on the Google-maintained GitHub repo for ESPv2. The folks there are responsive and helpful.

Upvotes: 1

Related Questions