Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gRPC-Web protocol #43

Closed
jakobr-google opened this issue Dec 20, 2017 · 65 comments
Closed

Support gRPC-Web protocol #43

jakobr-google opened this issue Dec 20, 2017 · 65 comments
Assignees

Comments

@jakobr-google
Copy link
Contributor

@jakobr-google jakobr-google commented Dec 20, 2017

See the gRPC-Web protocol document for details.

We should be able to support this by making a GrpcWebChannel that implements the ClientChannel interface.

@ghost
Copy link

@ghost ghost commented Feb 13, 2018

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.

@ghost
Copy link

@ghost ghost commented Mar 3, 2018

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.

@jakobr-google
Copy link
Contributor Author

@jakobr-google jakobr-google commented Mar 6, 2018

No-one is talking about nginx or c++ here. This issue is for implementing the gRPC-Web protocol in Dart.

@ghost
Copy link

@ghost ghost commented Mar 6, 2018

did not know :)

sounds good...

@sgon00
Copy link

@sgon00 sgon00 commented Mar 16, 2018

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:

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.

@jakobr-google
Copy link
Contributor Author

@jakobr-google jakobr-google commented Mar 16, 2018

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!

@sgon00
Copy link

@sgon00 sgon00 commented Mar 16, 2018

@jakobr-google Thank you very much for your quick reply and hard work. 👍

@ghost
Copy link

@ghost ghost commented Mar 16, 2018

@jakobr-google
Copy link
Contributor Author

@jakobr-google jakobr-google commented Mar 16, 2018

Just to make sure we're on the same page: Flutter is already supported. This issue is for adding support for web browsers, too.

@ghost
Copy link

@ghost ghost commented Mar 16, 2018

@pcariel
Copy link

@pcariel pcariel commented Mar 20, 2018

@jakobr-google this improvement will be compatible with Google Cloud Platform Endpoints ?

@jakobr-google
Copy link
Contributor Author

@jakobr-google jakobr-google commented Mar 22, 2018

@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

  1. 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.
  2. 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.

@leocavalcante
Copy link

@leocavalcante leocavalcante commented Mar 23, 2018

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.

@kevmoo
Copy link
Contributor

@kevmoo kevmoo commented Mar 23, 2018

@adrianmercieca
Copy link

@adrianmercieca adrianmercieca commented Mar 24, 2018

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...

@Brahmasmi
Copy link

@Brahmasmi Brahmasmi commented Mar 28, 2018

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.

@adrianmercieca
Copy link

@adrianmercieca adrianmercieca commented Mar 29, 2018

I second this; really look forward to have gRPC accessible from the browser via Dart.

@HeNKiEeEeE
Copy link

@HeNKiEeEeE HeNKiEeEeE commented Jun 2, 2018

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?

@Kleak
Copy link

@Kleak Kleak commented Jun 2, 2018

Yes it's not possible yet

@leocavalcante
Copy link

@leocavalcante leocavalcante commented Jun 2, 2018

@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.

@JCzz
Copy link

@JCzz JCzz commented Jun 5, 2018

Do we know if this is being worked on and if so, super cool - and when to expect?

@wav
Copy link

@wav wav commented Jun 6, 2018

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:

https://github.com/wav/grpc-web-dart/blob/717187ebfacdbf3f221e6cf39948ac265e69592e/lib/src/call.dart#L57

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.

@frankbenoit
Copy link

@frankbenoit frankbenoit commented Jun 15, 2018

Having a full implementation is for me the missing component to give dart and angulardart a trial in my company.

@ghost
Copy link

@ghost ghost commented Jun 20, 2018

@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....

@wav
Copy link

@wav wav commented Jun 21, 2018

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".

@ghost
Copy link

@ghost ghost commented Jul 30, 2018

Any updayrs on this ?

@glenfordwilliams
Copy link

@glenfordwilliams glenfordwilliams commented Nov 17, 2018

same here along with the pull request for proper json interop

@pbk0
Copy link

@pbk0 pbk0 commented Nov 18, 2018

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.

@GeertJohan
Copy link

@GeertJohan GeertJohan commented May 8, 2019

Support from the browser could now also benefit flutter applications that use https://github.com/flutter/flutter_web

@1l0
Copy link

@1l0 1l0 commented May 25, 2019

Q: Can a "Flutter for web" project using grpc-dart(non web) be built to deploy for the web?

@leocavalcante
Copy link

@leocavalcante leocavalcante commented May 25, 2019

@1l0 I don't think so, the lib is highly tied to dart:io Sockets.

@1l0
Copy link

@1l0 1l0 commented May 25, 2019

@leocavalcante Thanks.

@aaahrens
Copy link

@aaahrens aaahrens commented May 27, 2019

Any news on this?

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 18, 2019

I merged the grpc-web branch. It is now published in version 2.0.0

@sigurdm sigurdm closed this Jun 18, 2019
@joelmarks-wf
Copy link

@joelmarks-wf joelmarks-wf commented Jun 21, 2019

@sigurdm I am confused. grpc-dart is currently at v0.4.1 what is this 2.0.0 version you speak of?

@facundomedica
Copy link

@facundomedica facundomedica commented Jun 21, 2019

@joelmarks-wf you are seeing the releases on Github (that seems to be out of use). Check https://pub.dev/packages/grpc

@joelmarks-wf
Copy link

@joelmarks-wf joelmarks-wf commented Jun 21, 2019

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."?

@mit-mit
Copy link
Collaborator

@mit-mit mit-mit commented Jun 24, 2019

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!

@ligustah
Copy link

@ligustah ligustah commented Jun 25, 2019

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!

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 25, 2019

Have you tried v. 2.0.0+1 it should fix the issue you see with webdev?

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 25, 2019

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

@ligustah
Copy link

@ligustah ligustah commented Jun 25, 2019

Oh, hadn't seen the +1 release. I'll give it a shot later. Thanks a lot @sigurdm

@ligustah
Copy link

@ligustah ligustah commented Jun 26, 2019

Have you tried v. 2.0.0+1 it should fix the issue you see with webdev?

Worked!

@ghost
Copy link

@ghost ghost commented Jun 26, 2019

Is would be useful for everyone is there was an example that use GRPC-Web for FLutter Web, Desktop and Mobile.

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 26, 2019

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.

@ghost
Copy link

@ghost ghost commented Jun 26, 2019

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 26, 2019

It can use grpc, but not grpc-web.
Grpc-web makes http requests using dart:html.
Grpc makes http2 requests using dart:io sockets.

@ghost
Copy link

@ghost ghost commented Jun 26, 2019

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

@michaellee8
Copy link

@michaellee8 michaellee8 commented Jul 11, 2019

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.

@sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jul 12, 2019

Currently grpc web is tied to HttpRequest from dart:html. It should be possible to generalize it. I opened an issue #216.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet