Giter VIP home page Giter VIP logo

Comments (3)

jhump avatar jhump commented on June 3, 2024

Why don't you release a standalone grpc to JSON gateway?

So you are asking for something that just translates the protobuf binary payloads to JSON? FWIW, streaming and other gRPC protocol features such as compression would not really work well with this.

It sounds like maybe you are wanting a gRPC-web client that uses JSON, paired with a server that uses JSON. This is currently problematic because https://github.com/grpc/grpc-web uses a JS protobuf library that does not support JSON. So a few things you might instead consider:

  1. You could use https://github.com/bufbuild/connect-es to create gRPC-web clients that support JSON and then also use an encoding.Codec in your server that supports JSON (if you are using a Go server anyway). The Codec interface is easy to implement for JSON: the two methods map to functions of the same name in the protojson package.
  2. You could use Connect instead of gRPC. It supports JSON out of the box. (Implementations currently available in TS/JS, Go, Kotlin/Android, and Swift/iOS).

from grpcui.

idc77 avatar idc77 commented on June 3, 2024

I'm just looking for a way to consume the grpc server on a web frontend.
Idk what buf has to do with any of this. Everywhere I go in the grpc world I'm met with buf marketing.
Forget I asked, it was a stupid idea.
grpc is not fit for the web.

from grpcui.

jhump avatar jhump commented on June 3, 2024

I'm just looking for a way to consume the grpc server on a web frontend.

@idc77, the "official" answer from the gRPC team is probably to use gRPC-Web: https://github.com/grpc/grpc-web
However, it uses Protobuf binary encoding, not JSON (though it does have an option to use the Protobuf text format). The gRPC-Web protocol is a little different than gRPC so that it can support HTTP 1.1 and browser HTTP client capabilities. So it requires running a proxy in front of your gRPC server that translates from the gRPC-Web proxy. There is also an Envoy filter, so if you already run Envoy as an ingress/reverse proxy or as a sidecar (like in a service mesh), it can be configured to automatically translate gRPC-Web to gRPC.

grpc is not fit for the web.

You might check out Connect: it was designed for web and mobile use cases. So it should be a much better experience. It supports JSON, it has a curl-friendly protocol for unary RPCs, and works in web (TS/JS) and mobile (Kotlin and Swift).

from grpcui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.