purescript-protobuf icon indicating copy to clipboard operation
purescript-protobuf copied to clipboard

gRPC Services

Open jamesdbrock opened this issue 3 years ago • 9 comments
trafficstars

Issue for discussion of gRPC implementation.

https://developers.google.com/protocol-buffers/docs/proto3#services

https://grpc.io/docs/guides/

jamesdbrock avatar May 05 '22 14:05 jamesdbrock

Buffer instances are also JavaScript Uint8Array and TypedArray instances.

https://nodejs.org/docs/latest/api/buffer.html#buffers-and-typedarrays

jamesdbrock avatar May 05 '22 14:05 jamesdbrock

gRPC uses HTTP/2. https://grpc.io/docs/what-is-grpc/faq/#why-is-grpc-better-than-any-binary-blob-over-http2

There is this in Node.js https://nodejs.org/api/http2.html

But you cannot use HTTP/2 from browser? https://grpc.io/blog/state-of-grpc-web/

You can use gRPC from the browser with an HTTP/2 proxy https://grpc.io/docs/what-is-grpc/faq/#can-i-use-it-in-the-browser

jamesdbrock avatar May 30 '22 01:05 jamesdbrock

The Node.js HTTP/2 API exposes Readable and Writable Streams, so to make this simple we could generate code in terms of https://pursuit.purescript.org/packages/purescript-node-streams-aff

jamesdbrock avatar Jun 21 '22 17:06 jamesdbrock

gRPC over HTTP2

https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

“gRPC does not currently support/use PUSH_PROMISE.”

https://stackoverflow.com/a/56741574/187223

jamesdbrock avatar Jul 08 '22 08:07 jamesdbrock

@jamesdbrock have you made any progress on this so far? I'm looking for an alternative to PureScript that does not involve grpc Node bindings, but it seems I don't have many options.

klarkc avatar Nov 06 '23 12:11 klarkc

@klarkc Not really, I wrote https://github.com/purescript-node/purescript-node-http/pull/45 , which you have seen. Even with that HTTP/2 implementation, there would be more work to implement gRPC.

jamesdbrock avatar Nov 07 '23 14:11 jamesdbrock

What would this work entail? I'm very curious about this

i-am-the-slime avatar Feb 26 '25 20:02 i-am-the-slime

Well, now https://pursuit.purescript.org/packages/purescript-node-http2 exists, but in my opinion it's not very wieldy yet because the whole API is all Effect instead of Aff.

So, something like

  1. Write an Aff API package purescript-node-http2-aff depending on https://pursuit.purescript.org/packages/purescript-node-http2
  2. Write the gRPC code generator for purescript-protobuf plugin https://github.com/rowtype-yoga/purescript-protobuf/tree/master/plugin which generates calls to the purescript-node-http2-aff API.

Or we could try to revive https://github.com/purescript-node/purescript-node-http/pull/45

jamesdbrock avatar Feb 27 '25 06:02 jamesdbrock

If I were doing this personally for some project which needs PureScript gRPC, what I would actually do is

  1. Write an Aff API package purescript-node-http2-aff depending on https://pursuit.purescript.org/packages/purescript-node-http2 . I would use the API from https://github.com/purescript-node/purescript-node-http/pull/45 as a model. I put a lot of thought into that API and I think it's pretty good.
  2. Use purescript-protobuf to generate only the message code from the .proto files for my project.
  3. Manually write the gRPC stuff for my project from purescript-node-http2-aff and the generated message code.
  4. After I had manually written the gRPC stuff for one project, then I would have a good idea of what kind of PureScript needs to be generated for gRPC. So then I would write the gRPC code generator for purescript-protobuf plugin https://github.com/rowtype-yoga/purescript-protobuf/tree/master/plugin which generates calls to the purescript-node-http2-aff API.

jamesdbrock avatar Feb 27 '25 08:02 jamesdbrock