What you will have at the end
Two Routes for two protocols the gateway carries besides plain HTTP. hello-grpc takes a JSON body or a query string, turns it into a gRPC call to the hello service of the lab and turns the reply back into JSON, with the service’s proto definition kept as an object in the console. ws-echo lets a client upgrade its connection to WebSocket and exchange messages with a backend through the gateway, where the same request without the switch is a plain HTTP request the backend refuses. Both are request records in Traffic Explorer, and the proto, the Upstream and the Routes are in the audit log.
Prerequisites
- A gRPC service. The lab runs
grpcbin, which answershello.HelloService/SayHelloon port 9000 without TLS; a reply ishellofollowed by the greeting sent. - A backend that speaks WebSocket. The lab’s echo service answers
/websocket/echoby sending every message back; it is the Upstreamhttpbin-backendof the other articles. - Traffic logging turned on under Traffic Explorer › Settings, and a role that may manage Upstreams, Routes and protos. The screenshots below were taken as
nora.becker.
Part one: JSON in, gRPC out
The proto
Open Services › Protos in the Environment’s navigation and select New proto. The page says what the object is for: Routes that transcode JSON to gRPC read their services and messages from here. Name and Description are yours; Content takes the protobuf source text, or a compiled descriptor set as base64. The note under it is the one to read before pasting a file with imports: the content is compiled alone when you save, an import is refused, even of a well-known type, while a descriptor set that carries its imported files is accepted. A file that declares a service needs a package line, or the engine fails the save.
The article pastes the hello service, twelve lines: package hello, HelloRequest with a greeting, HelloResponse with a reply, and HelloService with SayHello.

Select Create proto. The proto’s page shows the content with its id, which the Plugin below picks from a list.
The Upstream
Under Upstreams, create grpcbin-backend with one node, grpcbin on port 9000, and Scheme grpc. The scheme is how the engine speaks to the nodes, and its help lists the choices: plain or TLS HTTP, gRPC with or without TLS, WebSocket, a raw stream, or Kafka. Without grpc here, the engine would send the transcoded call as HTTP/1.1 to a port that only speaks HTTP/2.

The Route and grpc-transcode
Create a Route, hello-grpc, with the path /grpc/hello, the methods GET and POST, and grpcbin-backend as its Upstream. Then Plugins, Add plugin, grpc-transcode:
- Proto ID: the proto, picked from the Environment’s list, with an Open proto link beside it. The More note is worth reading: an id the gateway does not hold is saved without complaint, and every request then reaches the upstream untranscoded, which a gRPC upstream answers with 502.
- Service:
hello.HelloService, the full name with the package. A name the proto does not define is also saved without complaint, and every request is answered 503. - Method:
SayHello. - Under Behavior, Protobuf options decide how enums, 64-bit integers and absent fields are written into the JSON, at most one word per family; Deadline is sent to the upstream with the call; Show status in body writes the decoded status details of a failed call into the response body as well.

Select Add plugin. Two calls with nothing but curl:
### POST /grpc/hello with a JSON body
HTTP/1.1 200 OK
Content-Type: application/json
Trailer: grpc-status
{"reply":"hello g8"}
grpc-status: 0
### GET /grpc/hello?greeting=... the same call as a query
HTTP/1.1 200 OK
Content-Type: application/json
{"reply":"hello from a query"}
The gateway read the body or the query as a HelloRequest, called the service over HTTP/2 and wrote the HelloResponse as JSON; the response also carries the gRPC status as a trailer, grpc-status: 0. The same port asked directly with HTTP/1.1 closed the connection without an answer; curl printed no status at all.
What the transcoder does not do is validate. A body with an unknown field, or a body that is not JSON at all, was turned into an empty HelloRequest and answered {"reply":"hello noname"}, the service’s reply to an empty greeting, with 200. A contract for the JSON side goes on the same Route with request-validation, from Request validation: JSON Schema and OpenAPI at the gateway, and runs before the transcoder.

Part two: a Route that upgrades to WebSocket
Create a Route, ws-echo, with the path /ws/echo and httpbin-backend as its Upstream, with proxy-rewrite sending /ws/echo to the backend’s /websocket/echo. Before anything else is set, a WebSocket handshake through the gateway:
### WebSocket handshake through the gateway, Websocket off on the Route
HTTP/1.1 400 Bad Request
{"status_code": 400, "error": "Bad Request", "detail": "missing required `Upgrade: websocket` header"}
The backend answered, and it did not see the upgrade: the gateway forwarded the request as plain HTTP and left the Upgrade header behind. Open the Route, Edit route, and under Target, beside the Upstream, switch Websocket on; its help is one line, it lets a matching request upgrade the connection to WebSocket.

Select Save route. The same handshake, and then a client:
### the same handshake, Websocket on
HTTP/1.1 101 Switching Protocols
Connection: upgrade
Upgrade: websocket
### from a browser page: new WebSocket("ws://localhost:9281/ws/echo"), three messages
open after 34 ms
echo: hello from the browser
echo: second message
echo: {"order":"ord-10421","status":"open"}
closed 1000
The client script is the four lines any browser runs: open the socket at the gateway’s address, send on open, read on message, close. Three messages went to the backend and came back through the gateway. For a message size limit, the Plugin websocket-proxy sets a client and an upstream limit on the Route; it was not needed here.

What the audit log keeps
Creating the proto is a proto.created record with the whole content as the engine received it; the Upstream is an upstream.created record with the node and the scheme; the Routes are route.created and, for the switch, a route.updated with enable_websocket as the difference. None of these objects holds a secret.

What to do next
- Put a contract on the JSON side of a transcoded call: Request validation: JSON Schema and OpenAPI at the gateway.
- Count and time the gRPC Route like any other: the Route’s Analytics tab and A failing backend out of rotation for the health checks on the gRPC Upstream.
- The protocol settings side by side are in the capabilities reference and on API Gateway.