- https://cloud.google.com/endpoints/docs/grpc/transcoding
- Type: reference
- Source: Google Cloud Endpoints documentation
TL;DR
Annotate each RPC with google.api.http so Cloud Endpoints’ proxy (ESP) maps REST-style HTTP/JSON requests onto gRPC methods.
What it covers
Transcoding is on by default (POST GRPC_SERVICE_FULL_NAME/METHOD_NAME), but explicit mappings give a cleaner HTTP interface. The page defines the annotation syntax, field mapping rules, the descriptor needed for deployment and the usual errors.
Key takeaways
- Annotate in the proto:
option (google.api.http) = { get: "/v1/shelves/{shelf}" };(alsopost, withbody). - Path captures fill request fields:
{shelf}is shorthand for{shelf=*}. body: "field"sends the JSON body into one field;body: "*"maps all fields not bound by the path.- Design resource-oriented APIs with List, Get, Create, Update and Delete; custom methods are harder to map.
- Build a descriptor:
protoc --include_imports --include_source_info --descriptor_set_out, with the googleapis clone forannotations.proto, thengcloud endpoints services deploy. - YAML alternative: rules under
http.rules(not supported by ESPv2). - Avoid errors: do not remap the default POST path (duplicate pattern), send valid field values only, and pass a single descriptor to
gcloud.
Tools and concepts
| Item | Role in the page |
|---|---|
| gRPC | Backend protocol |
| API | Resource-oriented REST surface |
| ESP / ESPv2 | Extensible Service Proxy that does the translation |
google.api.http | Annotation that defines the mapping |
When to use
- When adding a REST/JSON interface to a gRPC service on Google Cloud.
- When you need examples of path, query and body mapping.
- When comparing with gateway-side transcoding in Apache APISIX - Gateway transcode.
Caveats
- Tied to Cloud Endpoints (ESP); ports and flags differ between ESPv1 and ESPv2.
gRPC API Apache APISIX - Gateway transcode Introducing gRPC Support with NGINX