go-grpc-gateway


tags:

  • ready
  • online
  • reviewed
  • microservices
  • go
  • frameworks

grpc-gateway

Contents

__Roadmap info from [ roadmap website ] (https://roadmap.sh/golang/go-microservices/grpc-gateway) __

Grpc gateway

gRPC-Gateway creates a layer over gRPC services that will act as a RESTful service to a client.It is a plugin of protoc.It reads a gRPC service definition and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.Visit the following resources to learn more:

  • @opensource@Grpc-gateway Github

    gRPC-Gateway__

    • Purpose: Allows RESTful clients to interact with gRPC services.
    • Best For: Providing both REST and gRPC APIs for microservices.

    Example:

    mux := runtime.NewServeMux()
    err := pb.RegisterYourServiceHandlerFromEndpoint(ctx, mux, "localhost:50051", opts)
    

    gRPC-Gateway__ - RESTful API for gRPC Services

    Solution Example: Mobile Backend for Streaming Service

    • Use Case: A mobile app interacts with backend services using a REST API, but the backend communicates via gRPC.
    • Framework Usage: The gRPC-Gateway exposes a REST API for the mobile app, while internal services communicate using gRPC.
    • Workflow:
    1. The mobile app calls a REST endpoint via gRPC-Gateway.
    2. The gateway translates the REST request into a gRPC call to the StreamingService.

    Example:

    mux := runtime.NewServeMux()
    err := pb.RegisterStreamingServiceHandlerFromEndpoint(ctx, mux, "localhost:50051", opts)