grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
850 stars 267 forks source link

Support gRPC-Web protocol #43

Closed jakobr-google closed 5 years ago

jakobr-google commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

ghost commented 6 years ago

did not know :)

sounds good...

sgon00 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

ghost commented 6 years ago

+1 Thats exactly what i am looking to us it for too. Flutter

On Fri, 16 Mar 2018 at 09:48 sgon00 notifications@github.com wrote:

@jakobr-google https://github.com/jakobr-google Thank you very much for your quick reply and hard work. 👍

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-dart/issues/43#issuecomment-373643962, or mute the thread https://github.com/notifications/unsubscribe-auth/ATuCwoYK5Q-aXlZqZzNaRLABlRu89lswks5te3xXgaJpZM4RITAe .

jakobr-google commented 6 years ago

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 commented 6 years ago

Thanks. I should clarify then. The Client is Flutter and the Server is golang for me, so i have 2 requirements:

On Fri, 16 Mar 2018 at 11:29 Jakob Andersen notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-dart/issues/43#issuecomment-373671462, or mute the thread https://github.com/notifications/unsubscribe-auth/ATuCwsE7XaoH341uMFsbxcbjJGtL6dqRks5te5QGgaJpZM4RITAe .

pcariel commented 6 years ago

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

jakobr-google commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

So do I!

On Fri, Mar 23, 2018 at 11:21 AM Leo Cavalcante notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/grpc/grpc-dart/issues/43#issuecomment-375757670, or mute the thread https://github.com/notifications/unsubscribe-auth/AABCij3gZzHAUVubzuALPsNy9KgfoFgWks5thT0jgaJpZM4RITAe .

adrianmercieca commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

hlgrondijs commented 6 years ago

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 commented 6 years ago

Yes it's not possible yet

leocavalcante commented 6 years ago

@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 commented 6 years ago

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

wav commented 6 years ago

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 commented 6 years ago

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

ghost commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

Any updayrs on this ?

kevmoo commented 6 years ago

@gedw99 – nope. If a community member wanted to make a go at it, we'd love to discuss.

Brahmasmi commented 6 years ago

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] - https://github.com/grpc/grpc-web/issues/213

fuzzybinary commented 6 years ago

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.

Brahmasmi commented 6 years ago

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

[1] - https://dk.linkedin.com/in/jakobroland

fuzzybinary commented 6 years ago

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.

keertip commented 6 years ago

@nichite

mit-mit commented 6 years ago

@sigurdm has taken over from @jakobr-google

mit-mit commented 6 years ago

Some work for this is happening over in https://github.com/grpc/grpc-dart/pull/109

facundomedica commented 5 years ago

Any updates on this?

fuzzybinary commented 5 years ago

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?

fuzzybinary commented 5 years ago

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.

mit-mit commented 5 years ago

@sigurdm is out this week, but hoping he can look next week

JCzz commented 5 years ago

Very nice! How do we get this, if it is out?

Update: Maybe this and if, it looks close to something: https://github.com/grpc/grpc-dart/pull/109

frankbenoit commented 5 years ago

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.

kingwill101 commented 5 years ago

same here along with the pull request for proper json interop

pbk0 commented 5 years ago

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.

wstrange commented 5 years ago

https://grpc.io/blog/state-of-grpc-web

GeertJohan commented 5 years ago

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

1l0 commented 5 years ago

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

leocavalcante commented 5 years ago

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

1l0 commented 5 years ago

@leocavalcante Thanks.

aaahrens commented 5 years ago

Any news on this?

sigurdm commented 5 years ago

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

joelmarks-wf commented 5 years ago

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