Support gRPC-Web protocol
jakobr-google opened this issue ยท 65 comments
See the gRPC-Web protocol document for details.
We should be able to support this by making a GrpcWebChannel
that implements the ClientChannel
interface.
Last time I looked at this package I was informed that it's designed for flutter.
But if scope has now expanded to support http 2 and http 1.1 then the improbable grpc-web library should be looked at. It's much easier and imho more useful than the official grpc-web that uses c++ and nginx. Anyway..
I don't use dart on the server, but instead golang.
But if you want to support http 1.1 with grpc dart go have a look.
I use http 1.1 and a VPN entire provide security where I can't tolerate domains. For example in on premise projects and where the endpoint on both ends is a dynamic IP. In those cases a private dht is used as a closed DNS to match up addresses up to organisations.
Why am I waiting on about this ? Well Https is great and we all want security but for b2b and iot and p2p http2 is a blocker.
See the improbable git repo for a grpc-web implementation that support normal grpc and grpc with browsers using websockets to give bi-directional streaming.
This version also adheres to the spec.
It also has great interceptor integration for logging, tracing and metric using Prometheus and is heavily production battle tested as they say.
It's golang, not dart based but much easier and flexible than the nginx and cpp way.
No-one is talking about nginx or c++ here. This issue is for implementing the gRPC-Web protocol in Dart.
did not know :)
sounds good...
Hi, any updates and plans on this requirement?
I plan to use grpc/http2 only (displacement of old http1 REST and websockets) in a new flutter project. For web interface, I plan to try angulardart v5 because it uses the same dart language. But after some research, I found out there were no native dart grpc-web support.
So far, I found out:
- The available gRPC servers that exposes services over gRPC-Web protocol to modern browsers:
- nginx with gRPC-Web support built from https://github.com/grpc/grpc-web (private repo)
- a standalone Go binary proxy
- caddy server through grpc plugin which uses the above Go package
- envoy through gRPC-Web http filter
- The available gRPC-Web clients
- Javascript and Typescript
- Vue.js
- GopherJS
- AngularDart is missing here!!!
To workaround it, I may try to use js_facade_gen
tool to generate Dart code for the improbable typescript client. I am not sure if this will work or not.
I hope angulardart can have its own native gRPC-Web protocol support soon. Thanks a lot.
Sounds like there's a lot of interest for this, so I've moved it up on my list of priorities. Absolutely no guarantees, but I expect to start looking at it around end of next week.
In the meantime, if anyone wants to pitch in, I'll happily take PRs for this!
@jakobr-google Thank you very much for your quick reply and hard work. ๐
Just to make sure we're on the same page: Flutter is already supported. This issue is for adding support for web browsers, too.
@jakobr-google this improvement will be compatible with Google Cloud Platform Endpoints ?
@pcariel from what I can tell, for Cloud Endpoints, you configure a REST/JSON mapping that you can use from the browser, instead of talking gRPC. It doesn't look like they support gRPC-Web, AFAICT, so fixing this issue won't help with that, unfortunately.
For those following this issue, please keep in mind that
- The gRPC protocol is based on HTTP/2, and as such does not currently work in browsers, since they don't expose HTTP/2 semantics.
- The gRPC-Web protocol is not the same as gRPC. It requires you to run a proxy that will accept the gRPC-Web protocol calls from the browser, and translate them into real gRPC calls to the server. This gRPC-Web proxy will need to run somewhere (preferably on the same domain as the web app, so you don't have to deal with CORS). If you're really lucky, the gRPC server you're talking to might support gRPC-Web natively, in addition to gRPC.
This issue tracks adding support for a gRPC-Web client channel, as well as server support for gRPC-Web.
I want to live in a world where your gRPC Dart server could serve your Flutter app and your AngularDart web-app without any hassle.
Hi,
I'm really excited by all this; it would be great to also have Dart Web support for gRPC. We could then write all our back-end services using gRPC (using any supported implementation language) and access it from clients built using Dart from both Flutter and Dart web.
Really this becomes a reality; watching this space...
Am I correct in my understanding that the planned gRPC-Web client channel functionality will work with AngularDart on the browser?
I ask this because I am in actual need of the gRPC-Web client channel functionality for an AngularDart web app, and was leaning towards @improbable-eng's Typescript based gRPC-Web.
As the previous posters have alluded to, adding gRPC-Web client channel natively to Dart would essentially nearly complete the common communication stack. It would nicely complement @improbable-eng's Go proxy.
I look forward to this functionality.
I second this; really look forward to have gRPC accessible from the browser via Dart.
I also wanted to use GRPC in my angulardart app, to communicate with a remote service. As I understand from here its not possible yet?
Yes it's not possible yet
@HeNKiEeEeE it is not trivially possible yet, but you still can run your gRPC server behind a gRPC-Web enabled proxy like Nginx, Envoy or gRPC Web Proxy from Improbable and rely on Dart's JS interop on the client.
Do we know if this is being worked on and if so, super cool - and when to expect?
I have an initial attempt here wav/grpc-web-dart at a client over HTTP/1.1. It does basic RPC against a golang server. It's used in a flutter app to get through a firewall.
The part that calls the HttpClient would need to switch to XHR if in the browser here:
It's just a simple request and response once you parse the protocol message data.
I may continue it when I get a bit more time.
Having a full implementation is for me the missing component to give dart and angulardart a trial in my company.
@wav why did you say "to get through a firewall" ? normal grpc uses port 443 ( if secure). Would that not also get through a firewall . Just want to understand and learn....
Currently I'm working in a MS environment.
I took the approach of using HTTP/1.1 as a "non deep investigative" approach to getting the app through a few environments where I cannot use HTTP/2.
In this case it's a "perimeter" firewall/proxy/...? serving several sites on the same port inside a company network. The certificate is configured there. It appears to do packet inspection and doesn't seem to like HTTP/2 (it proxies many websites on the same port). I haven't worked out why.
If I try open an HTTP/2 TLS connection it doesn't work either. Again, I haven't worked out why. Other golang apps are fine.
Also, if I want to put it behind IIS or run it in an App Service in Azure only HTTP/1.1 traffic seems to get through. In this environment, I also don't use a TLS connection as it's handled by the "perimeter".
Any updayrs on this ?
@gedw99 โ nope. If a community member wanted to make a go at it, we'd love to discuss.
In light of @kevmoo's helpful comment above, I have opened an issue with the gRPC web team [1] requesting support for Dart / AngularDart. I would request all volks who wish to see gRPC-web support to please share your thoughts on that issue.
Thanks.
[1] - grpc/grpc-web#213
Hey @kevmoo / @jakobr-google
Looking through the code, it looks like ClientChannel is fairly simple at the moment, but it looks like it could expand to do multiple connections / load balancing -- does it make sense to setup ClientConnection as an abstract class / interface and either provide a factory method to ClientChannel or have it decide based off environment which type of connection to create?
If so that could be a simple first step towards getting gRPC-Web capabilities.
@fuzzybinary I am not sure whether @jakobr-google is still with Google. Based on my limited understanding, I think Jakob may have moved on from Google [1]. If I am not wrong, Jakob was looking after HTTP/2, Protobuf as well as gRPC for Dart.
Sure does look like that! Hopefully this will get picked back up as a priority at some point. It appears @sigurdm has access to merge pull requests - hopefully at some point someone will be able to look over my PR and give feedback.
I can be patient until then though.
@sigurdm has taken over from @jakobr-google
Any updates on this?
I think the initial PR is ready for review, but the unit tests are failing (but not sure why). @sigurdm can you take a look?
Got around to fixing the unit tests for this, so now I think just looking for some comments on the PR to see if it can be pulled in.
Very nice!
How do we get this, if it is out?
Update: Maybe this and if, it looks close to something: #109
I check this issue each week, currently a bit worried as it is silent since some time. Please give it a push, this is a big thing IMO.
This feature opens browser application a properly typed API to the backend. A real "now i want to try Dart" argument.
same here along with the pull request for proper json interop
I want grpc backend built with python and access it with frontend designed with AngularDart. I suppose that grpc-web needs to be supported for AngularDart. This issue seems to get grpc-web support for grpc-dart. Sorry for being naive at this, but please help me understand, am I missing something.
In case I am looking at wrong place please help me understand how I can get AngularDart base web frontend access grpc backend designed in python.
Support from the browser could now also benefit flutter applications that use https://github.com/flutter/flutter_web
Q: Can a "Flutter for web" project using grpc-dart(non web) be built to deploy for the web?
@1l0 I don't think so, the lib is highly tied to dart:io
Sockets.
@leocavalcante Thanks.
Any news on this?
I merged the grpc-web branch. It is now published in version 2.0.0
@sigurdm I am confused. grpc-dart is currently at v0.4.1 what is this 2.0.0 version you speak of?
@joelmarks-wf you are seeing the releases on Github (that seems to be out of use). Check https://pub.dev/packages/grpc
Ahhh. Great! Does that mean you can remove the last part from https://pub.dev/packages/grpc#notes "It currently supports the the Flutter and Dart native platforms. The potential addition of gRPC-Web is tracked in issue 43."?
We still need to do a bit more testing before we declare this fully done, but yes there should be enough here for testing. Do let us know if you try it, and how that worked!
I tried it for one of my pet projects and it mostly worked like a charm, so thanks for that!
One of the issues is that it doesn't seem to work with more recent versions of the toolchain around webdev
. Using these version:
webdev: 2.2.0
build_runner: 1.6.0
build_web_compilers: 2.1.1
Dart VM version: 2.3.2 (Tue Jun 11 15:29:47 2019 +0200) on "macos_x64"
I get this message when I run webdev serve
:
[WARNING]build_web_compilers:entrypoint on web/main.dart: Skipping compiling tap|web/main.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:
grpc|lib/src/client/transport/http2_credentials.dart
grpc|lib/src/shared/security.dart
googleapis_auth|lib/src/oauth2_flows/auth_code.dart
https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings
and my app doesn't run. Haven't tried building with dart2js, though. I moved to these version to make it work:
webdev: 1.0.0
build_runner: 1.3.3
build_web_compilers: 1.2.2
Dart VM version: 2.3.2 (Tue Jun 11 15:29:47 2019 +0200) on "macos_x64"
With these versions there are no warnings and the app works just fine in the browser.
The only other issue I ran into was with a bidirectional stream endpoint I had in my files. It sort of worked for one message, but then behaved really weird and often times would just disconnect. From what I understand it's not currently supported by the grpc-web spec. Also I used the improbable implementation embedded in my go application, which also explicitly states that this is not supported.
Maybe it would be possible to directly throw an exception in case someone tries to use such an endpoint over a grpc-web channel.
Other than that it worked great and simplified my code base a lot. Awesome work!
Have you tried v. 2.0.0+1 it should fix the issue you see with webdev?
Maybe it would be possible to directly throw an exception in case someone tries to use such an endpoint over a grpc-web channel.
Good point. I filed #200
Have you tried v. 2.0.0+1 it should fix the issue you see with webdev?
Worked!
Is would be useful for everyone is there was an example that use GRPC-Web for FLutter Web, Desktop and Mobile.
Is would be useful for everyone is there was an example that use GRPC-Web for FLutter Web, Desktop and Mobile.
In the current form you cannot use grpc-web from flutter Desktop.
I'm not sure we have the resources to maintain another example currently. But would welcome external contributions.
It can use grpc, but not grpc-web.
Grpc-web makes http requests using dart:html.
Grpc makes http2 requests using dart:io sockets.
Ok makes sense. Thanks for the clarification.
So the trick will be to use grpc for flutter mobile and desktop and grpc-web for flutter web.
I will work up a demo and post as a new issue
Is there any way to use grpc-web protocol in Flutter mobile apps?
My use case is a forum application that is very likely to be attacked using DDOS or other vectors, so I would have to use Cloudfare to protect my endpoints, but I still want to leverage the goodness in gRPC. However, Cloudfare does not support the HTTP/2 protocol that normal gRPC uses.