Exploring the Power of
gRPC-Gateway for Writing RESTful Services
Rajiv Ranjan Singh
India 🇮🇳
GNOME Asia 2023
Kathmandu, Nepal


Rajiv Ranjan Singh
Software Engineer @ A.P. Moller - Maersk
I graduated in August, 2022 from JSSATE Bengaluru, India

GSoD 2020 @gRPC-Gateway
GSoD 2021 @Wechaty
LFX Mentorship 2021 @moja global
GSoC 2022 @Keptn
GSoC Mentor 2023 @Jenkins
Agenda
Prerequisites: gRPC, HTTP/JSON, Protobuf
- REST and gRPC
- gRPC-Gateway
- How to use gRPC-Gateway

REST and gRPC
gRPC doesn't have a default speed advantage over REST, but it provides features that can help enhance its speed.
- selective message compression
- load balancing
- etc
We all know that gRPC is not a tool for everything. There are cases where we still want to provide a traditional HTTP/JSON API. The reasons can range from maintaining backward compatibility to supporting programming languages or clients not well supported by gRPC. But writing another service just to expose an HTTP/JSON API is quite a time-consuming and tedious task.

The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.
This helps you provide your APIs in both gRPC and HTTP/JSON format at the same time.
gRPC-Gateway

- A plugin of protobuf compiler
- Generate proxy codes from protobuf
- Translates HTTP JSON Call to gRPC
- In-process translation: only for unary gRPC
- Separate proxy server: both unary and streaming gRPC
gRPC-Gateway

gRPC-Gateway

gRPC-Gateway

How to use gRPC-Gateway
- Defining Hello World gRPC service using protocol buffers.
- Creating
main.gowhere we will write our client and server logic. - Adding gRPC-Gateway annotations to an existing proto file.
- Generating the gRPC-Gateway stubs.

References


Thank You, 🙏 🎉
Portfolio: https://iamrajiv.github.io
GitHub: https://github.com/iamrajiv
LinkedIn: https://www.linkedin.com/in/iamrajivranjansingh
Twitter: https://twitter.com/therajiv
GNOME Asia 2023
By Rajiv Ranjan Singh
GNOME Asia 2023
- 121