Friday, May 17, 2024
HomeGolangGolang gRPC to JSON proxy generator following the gRPC HTTP spec

Golang gRPC to JSON proxy generator following the gRPC HTTP spec


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 interprets a RESTful HTTP API into gRPC. This server is generated in keeping with the google.api.http annotations in your service definitions.

This helps you present your APIs in each gRPC and RESTful fashion on the identical time.

Docs

You may learn our docs at:

Testimonials

We use the gRPC-Gateway to serve thousands and thousands of API requests per day, and have been since 2018 and thru all of that, now we have by no means had any points with it.

– William Mill, Advert Hoc

Background

gRPC is nice — it generates API purchasers and server stubs in lots of programming languages, it’s quick, easy-to-use, bandwidth-efficient and its design is combat-proven by Google. Nevertheless, you may nonetheless wish to present a conventional RESTful JSON API as effectively. Causes can vary from sustaining backward compatibility, supporting languages or purchasers that aren’t effectively supported by gRPC, to easily sustaining the aesthetics and tooling concerned with a RESTful JSON structure.

This venture goals to supply that HTTP+JSON interface to your gRPC service. A small quantity of configuration in your service to connect HTTP semantics is all that’s wanted to generate a reverse-proxy with this library.

Set up

Compile from supply

The next directions assume you’re utilizing Go Modules for dependency administration. Use a software dependency to trace the variations of the next executable packages:

// +construct instruments

bundle instruments

import (
    _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
    _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
    _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
    _ "google.golang.org/protobuf/cmd/protoc-gen-go"
)

Run go mod tidy to resolve the variations. Set up by operating

$ go set up 
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway 
    github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 
    google.golang.org/protobuf/cmd/protoc-gen-go 
    google.golang.org/grpc/cmd/protoc-gen-go-grpc

This may place 4 binaries in your $GOBIN;

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments