$ show grpc/grpc-web
This repository provides the grpc-web JavaScript/TypeScript client runtime and a protoc plugin for generating browser-compatible gRPC client stubs. It enables browser clients to communicate with gRPC services through an HTTP/1.1 proxy (Envoy or grpcwebproxy) by implementing the gRPC-Web protocol. The codebase includes a runtime library (npm package `grpc-web`) with support for unary and server-streaming calls, interceptors, metadata, deadlines, and two wire formats (grpcwebtext, grpcweb). The protoc plugin (`protoc-gen-grpc-web`) is a C++ binary that outputs client code in Closure, CommonJS, or TypeScript styles. Examples and interop tests demonstrate end-to-end usage with Node.js backends, Envoy proxy, and browser clients. The project is now in maintenance mode (no new features) with several drift risks: dual implementation (Closure JS and TypeScript), archived dependencies (Closure library, Protobuf JS), and incomplete TypeScript migration. Despite this, the core components are well-architected and the gRPC-Web stream parser and interceptor pattern are reusable.
The LLM identified 3 files worth highlighting for reuse:
Implements an incremental parser for gRPC-Web wire frames (0x00 data, 0x80 trailer) with automatic length decoding and configurable max message size protection. Self-contained and could be extracted for any project needing to parse gRPC-Web frames from a binary or text stream. Demonstrates careful state machine design and safe buffer management.
Defines both UnaryInterceptor and StreamInterceptor interfaces with a chain implementation using reduce to compose interceptors. The pattern is generic and separate from gRPC specifics – it can be reused in any client library that needs to chain request/response transformations. Demonstrates clean functional composition with Promise-based and callback-based chains.
A protoc plugin that generates JavaScript/TypeScript client stubs from protobuf service definitions. It uses protobuf's compiler plugin interface (CodeGenerator) and outputs code in multiple import styles (Closure, CommonJS, TypeScript) and wire formats. The implementation demonstrates the canonical pattern for writing a protoc plugin in C++, including handling service methods, field descriptors, and custom codegen options. While not easily extractable due to protobuf dependencies, it serves as a reference for any gRPC-Web codegen.