🔌 gRPC Intermediate

What is gRPC-web and why is it needed?

Answer

gRPC-Web is a variant of the gRPC protocol designed for use in web browsers. Standard gRPC requires HTTP/2 features (trailing headers) that browser XHR/Fetch APIs don't expose, making it impossible to use gRPC directly from browser JavaScript. gRPC-Web works by: (1) Using HTTP/1.1 or HTTP/2 without trailing headers, using a different framing; (2) Requiring an Envoy proxy (or grpc-web proxy) between browser clients and gRPC servers — the proxy translates gRPC-Web protocol to standard gRPC; (3) Supporting only unary and server-streaming (client streaming and bidirectional streaming are not supported). The @improbable-eng/grpc-web or official grpc-web npm package provides the browser client. For applications that need full streaming in the browser, WebSockets or native gRPC (via Envoy) are alternatives. gRPC-Web is well-suited for web frontends that call backend microservices.