1

I have a number of microservices that are both REST and gRPC. I'm planning to create a simple API gateway in Go so that a server in my local machine can access these microservices through 1 entry. The purpose is for development, i.e when I develop a new microservice, I don't have to re-create all its dependencies, I can just access it from a test server's API gateway that already have them all deployed.

Say I have two services:

  • ArticleService - a simple REST API with JSON request and response
  • UserService - a gRPC service accepting and returning protobufs

I want the gateway to be able to reverse proxy to these services, such as:

  • At {IP}/articles, it will direct to ArticleService (JSON request)
  • At {IP}/user, it will direct to UserService (request to {IP}/user is sent in protobuf, not JSON)

Unfortunately, I couldn't find much resource on how to write a HTTP2 server that can decode the data frames, read the path, and forward the request to a gRPC service. The only thing I could find is grpc-gateway but it's more of a reverse proxy for JSON request to gRPC service, instead of direct protobuf request.

Any help would be appreciated. Thanks!

hskris
  • 101
  • 4
  • 1
    have you considered using nginx or haproxy to route the requests to the backend services? I may just not be understanding your need fully, but it seems that you wouldn't need to write a custom go api gateway to accomplish this. – jmoney Jun 12 '23 at 16:37
  • Seems like there is already some solutions. If you are deploying these into K8s, you can consider LoadBalancer/Ingress Controllers like Traefik (https://traefik.io/) – Mayukh Sarkar Jun 12 '23 at 18:39
  • @jmoney yes i did, but the reason I go with this approach is for easier configuration. For example, say I want to add new routes for a new microservice. In Nginx or Haproxy, i would need to directly change the config files. But in Go API gateway, I am able to store the routes data in a JSON or a database, and I won't need to change the API gateway app at all. – hskris Jun 13 '23 at 04:24

0 Answers0