Book Image

Practical gRPC

By : Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare
Book Image

Practical gRPC

By: Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare

Overview of this book

While building systems that contain several components, you need a framework that is fast and has minimal network overhead. gRPC is one such open-source tool that is quickly becoming popular and gaining popularity with programmers. Practical gRPC introduces you to gRPC and explains how it compares and contrasts with similar technologies. You’ll be introduced to key technologies such as Protocol Buffers, and work your way up from basic gRPC usage, all the way through to its more advanced capabilities. You’ll learn the best practices for defining and evolving your gRPC APIs, and discover how different tools can be leveraged to get the most out of gRPC and even extend it. By the end of this book, you'll have all the information you need to get started building systems with gRPC.
Table of Contents (13 chapters)
11
11. Extending gRPC services

gRPC Gateway

The web over the last few years has been consistently moving to a Frontend > Backend model where the backend is nothing more than a JSON API that JavaScript in the browser uses to render the page. Since gRPC relies on HTTP/2 as the transport, this means browsers can’t hit a gRPC server directly.

Since gRPC uses well defined messages and services with the protobuf definition language, you can easily generate code from these definitions. Using a tool called “grpc-gateway” you can actually make a fully functional JSON server that forwards requests to a running gRPC server. It handles the transcoding of the provided JSON to gRPC and vise versa.

grpc-gateway-flow

From: https://github.com/grpc-ecosystem/grpc-gateway

Starting on the left, we define our protobufs and then generate a reverse proxy from them using the grpc-gateway tool. The tool will generate all of the endpoints in the protobuf’s “Service” definitions. From here, API clients (such as AJAX...