purescript-protobuf
purescript-protobuf copied to clipboard
gRPC Services
Issue for discussion of gRPC implementation.
https://developers.google.com/protocol-buffers/docs/proto3#services
https://grpc.io/docs/guides/
Buffer instances are also JavaScript Uint8Array and TypedArray instances.
https://nodejs.org/docs/latest/api/buffer.html#buffers-and-typedarrays
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
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
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 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 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.
What would this work entail? I'm very curious about this
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
- Write an
AffAPI package purescript-node-http2-aff depending on https://pursuit.purescript.org/packages/purescript-node-http2 - 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
If I were doing this personally for some project which needs PureScript gRPC, what I would actually do is
- Write an
AffAPI 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. - Use purescript-protobuf to generate only the message code from the
.protofiles for my project. - Manually write the gRPC stuff for my project from purescript-node-http2-aff and the generated message code.
- 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.