DEV Community

greymoth
greymoth

Posted on

One port, two protocols: gRPC + REST with Connect-RPC in Rust

When we built the guardian service for kairon.trade, we had the usual dilemma: ship a gRPC API for internal services, or a REST/JSON API for browser clients. Both have merit. Running two separate servers doubles the surface area.

Connect-RPC solved this cleanly.

What Connect-RPC does

Connect is a protocol that runs on HTTP/1.1 and HTTP/2. A single handler can serve:

  • gRPC clients (HTTP/2, binary protobuf)
  • gRPC-web clients (HTTP/1.1, protobuf or JSON)
  • Connect clients (HTTP/1.1 or HTTP/2, JSON or protobuf)

Content-type negotiation happens transparently. The handler code is protocol-agnostic.

The setup

kairon-guardian is written in Rust. We use the connectrpc crate to expose services defined in .proto files as both gRPC and REST/JSON endpoints on a single :9000 listener.

No Envoy. No sidecar. No port split. One binary, one port, two protocols.

Why this matters

Before: internal Rust services spoke gRPC, browser clients needed a separate REST layer with its own routing, serialisation, and error handling.

After: both hit the same handler. The proto definition is the single source of truth for request/response shape across both transports.

The build-time overhead is protobuf generation - worth it for eliminating the translation layer entirely.


kairon.trade - building prediction market tooling in public.

GitHub: github.com/greymoth-jp

Top comments (0)