gitmyhub

grpc-web

JavaScript ★ 9.2k updated 12d ago

gRPC for Web Clients

A JavaScript library that lets web browsers call backend gRPC services through an Envoy proxy, bridging the gap between browser web protocols and the gRPC communication standard used between microservices.

JavaScriptProtocol BuffersgRPCEnvoysetup: hardcomplexity 4/5

gRPC-web is a JavaScript library that allows web browser applications to talk directly to backend services using a communication system called gRPC. gRPC is a way for programs to call functions or request data from other programs running on different machines, commonly used between microservices in larger software systems. Traditionally, browsers cannot use gRPC directly because of how web protocols work, so gRPC-web bridges that gap.

The way it works is that the browser client sends requests to a proxy server (by default, one called Envoy), which translates the web-compatible messages into standard gRPC calls and forwards them to the actual backend service. The proxy handles the protocol translation in the middle, so the backend service does not need to know it is talking to a browser.

To use the library, developers define their service's data structures and methods in a file format called Protocol Buffers (a way to describe what data looks like and what operations are available). A code generator then reads that definition and produces JavaScript files containing the client code needed to make those calls from the browser. The developer includes those generated files in their web application and calls the methods directly in JavaScript.

The library currently supports two calling patterns: sending a single request and getting a single response (called a unary call), and receiving a stream of responses from the server after sending one request (server-side streaming). Client-to-server streaming and fully bidirectional streaming are not yet supported.

The npm package is the main way to install the runtime library. Docker-based example projects are included in the repository for developers who want to see a working setup before building their own.

Where it fits