grpc-gateway

A protoc plugin that generates a reverse-proxy server, turning RESTful HTTP/JSON requests into gRPC calls from the same service definitions.

Tool
Go
vv2.31.0
20,004 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
94 /100 Excellent
Development Activity 96
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 88
Code Quality 90
Innovation 78
Learning Curve 75

grpc-gateway reads protobuf service definitions annotated with google.api.http options and generates a reverse-proxy server that translates a RESTful HTTP+JSON API into gRPC calls. Instead of hand-writing and maintaining a parallel REST API alongside a gRPC service, teams add HTTP annotations to their .proto files and let the generator produce the routing, request decoding, and response marshaling code automatically.

The project ships as a protoc/buf code-generation plugin (protoc-gen-grpc-gateway) alongside a runtime package that the generated code imports for request multiplexing, JSON/protobuf marshaling, error handling, and field-mask support. A companion plugin, protoc-gen-openapiv2, emits Swagger/OpenAPI 2.0 documentation from the same annotations, and an alpha protoc-gen-openapiv3 plugin does the same for OpenAPI 3.1 — so one set of proto definitions can drive gRPC, REST, and API documentation together.

What You Get

  • A protoc/buf plugin (protoc-gen-grpc-gateway) that generates a Go reverse-proxy server from google.api.http annotations in .proto files
  • A runtime package (ServeMux, marshalers, error handling, field masks) that the generated proxy code depends on at runtime
  • protoc-gen-openapiv2 for generating Swagger/OpenAPI 2.0 specs from the same proto annotations
  • An alpha protoc-gen-openapiv3 plugin for OpenAPI 3.1 output
  • Configurable JSON marshaling (jsonpb-compatible), custom error handlers, and pluggable header/metadata mapping between HTTP and gRPC

Common Use Cases

  • Exposing an existing internal gRPC service to external clients (browsers, mobile apps, third-party integrators) as a JSON REST API without duplicating business logic
  • Providing backward-compatible REST endpoints while migrating a service to gRPC internally
  • Generating OpenAPI/Swagger documentation automatically from proto definitions for API consumers who expect REST tooling
  • Building a single API gateway in front of multiple gRPC microservices that also needs to speak HTTP/JSON to edge clients

Under The Hood

Architecture The project is split into a code generator and a runtime library that the generated code depends on. protoc-gen-grpc-gateway/main.go is a thin protoc/buf plugin entry point that hands the CodeGeneratorRequest to an internal generator package, which walks each proto service’s methods, reads their google.api.http annotations, and emits Go source defining HTTP routes bound to gRPC client calls. At runtime, the generated RegisterXHandler functions register those routes on a runtime.ServeMux (in the runtime package), which is a purpose-built HTTP multiplexer — not net/http.ServeMux — that matches path patterns extracted from the annotations, decodes query/body parameters into protobuf messages via pluggable Marshalers, and forwards the resulting call through a standard gRPC client connection. A parallel protoc-gen-openapiv2/protoc-gen-openapiv3 plugin walks the same annotated proto files through a separate internal generator to emit OpenAPI documents, sharing the annotation-parsing layer but not the runtime request path. This separation — codegen-time route extraction, runtime-time request translation — means the generated proxy has no reflection or annotation parsing cost at request time; everything is resolved to concrete route matching and message construction ahead of time.

Tech Stack The module (github.com/grpc-ecosystem/grpc-gateway/v2) targets modern Go (go 1.26 in go.mod) and builds on google.golang.org/grpc and google.golang.org/protobuf as its core runtime dependencies, with google.golang.org/genproto for well-known API types. JSON marshaling defaults route through protobuf’s own JSON mapping rules with a jsonpb-compatible Marshaler interface, and the go-openapi family (errors, runtime, strfmt, swag, validate) backs the OpenAPI validation tooling. Observability is first-class: go.opentelemetry.io/otel and its otelgrpc/otelhttp instrumentation packages are direct dependencies, letting generated proxies emit traces across the HTTP-to-gRPC hop out of the box. The repo supports both Go modules and Bazel (BUILD.bazel, WORKSPACE, MODULE.bazel) as build systems, and CI runs through GitHub Actions with Renovate managing dependency updates automatically.

Code Quality The project carries an extensive test suite (over 50 _test.go files across runtime, the generator internals, and the OpenAPI plugins), including dedicated tests for edge cases like path unescaping modes, field masks, and marshaler registry behavior. go.mod declares honnef.co/go/tools/cmd/staticcheck as a tracked tool dependency, indicating static analysis is part of the standard workflow, and a .github/workflows/ci.yml pipeline runs the suite on every change. Error handling is explicit and typed throughout the runtime package (a dedicated errors.go maps gRPC status codes to HTTP responses rather than relying on generic error strings), and naming conventions follow standard Go idioms (exported ServeMux, Marshaler, HandlerFunc types with doc comments). A CONTRIBUTING.md and Slack community channel support external contributions, and the project has 470+ contributors, suggesting sustained external review pressure on code quality over time.

API Design The public API centers on a small set of well-documented primitives — runtime.NewServeMux, the Marshaler interface, and generated RegisterXHandler(FromEndpoint) functions — that keep the integration surface narrow even though the internal routing logic is substantial. Configuration is done through functional options passed to NewServeMux (for example WithMarshalerOption, WithUnescapingMode, WithErrorHandler), a idiomatic Go pattern that keeps the common case (default JSON marshaling, standard routing) a one-line call while still exposing deep customization for teams with nonstandard requirements. The tradeoff is upfront proto-annotation overhead: getting a working gateway requires learning the google.api.http annotation syntax and running an extra codegen step in the build, which is a real learning curve compared to hand-rolling REST handlers, but it keeps the REST surface mechanically derived from — and impossible to drift from — the gRPC service definition.

Used by 18 apps in this directory

Go
85%
Apache 2.0

Argo Workflows

Data Engineering · Devops

17,006

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
96
Repo Health
90
Technical
68
Dependency
Built with
Go 85%
TypeScript 11%
Updated 1 weeks ago
Go
84%
AGPL 3.0

Beta9

AI Development · Automation · Data Engineering

1,794

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
85
Repo Health
78
Technical
66
Dependency
Built with
Go 84%
Python 15%
Updated 1 weeks ago
Go
49%
MIT

Bytebase

Devops

14,512

An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.

View details
92
Repo Health
73
Technical
68
Dependency
Built with
Go 49%
TypeScript 42%
Updated 1 weeks ago
Go
74%
Other

Flipt

Developer Tools · Devops

4,911

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
69
Dependency
Built with
Go 74%
TypeScript 25%
Updated 1 weeks ago
Go
74%
Other

Flipt

Developer Tools · Devops

4,911

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
69
Dependency
Built with
Go 74%
TypeScript 25%
Updated 1 weeks ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 1 weeks ago
Go
51%
MIT

memos

Note Taking

63,382

Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.

View details
91
Repo Health
78
Technical
65
Dependency
Built with
Go 51%
TypeScript 48%
Updated 1 weeks ago
Go
95%
Apache 2.0

Nakama

Developer Tools · Game Development

13,422

Open-source game backend server with built-in multiplayer, matchmaking, leaderboards, chat, authentication, and storage — deploy anywhere via Docker or binary.

View details
89
Repo Health
73
Technical
73
Dependency
Built with
Go 95%
Updated 2 weeks ago
Go
95%
Other

NetBird

Security

29,568

Replace your VPN with a zero-trust WireGuard overlay network that auto-connects devices, enforces SSO and posture checks, and deploys in under 5 minutes.

View details
91
Repo Health
82
Technical
66
Dependency
Built with
Go 95%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers