11
votes

Upon discovering gRPC, I stumbled across this blog post

Why isn’t everyone already using gRPC in their SPAs?

Traditionally it’s not been possible to use gRPC from browser-based applications, because gRPC requires HTTP/2, and browsers don’t expose any APIs that let JS/WASM code control HTTP/2 requests directly.

But there is a solution! gRPC-Web is an extension to gRPC which makes it compatible with browser-based code (technically, it’s a way of doing gRPC over HTTP/1.1 requests). gRPC-Web hasn’t become prevalent yet because not many server or client frameworks have offered support for it… until now.

ASP.NET Core has offered great gRPC support since the 3.0 release. And now, building on this, we’re about to ship preview support for gRPC-Web on both server and client. If you want to dig into the details, here’s the excellent pull request from James Newton-King where it’s all implemented.

There is some good information here, but the post is around a year old at this point.

There are also some major pushes from Microsoft with .NET and Blazor technology recently.

It looks like grpc-web is pretty well maintained and always adding a lot of language support, so that's something to keep an eye on... but as I understand it grpc-web is still built to operate over HTTP1.1?

For me, another question that still remains why HTTP2 is not supported through browser APIs, to which I cannot find any documentation on.

I would love to start using gRPC, but am also concerned about the cons that might come with it.

Thank you for any explanations to my lack of understanding.

Note there is a slightly related question on SO about this here, to which the answers were not totally comprehensive and older.

1

1 Answers

8
votes

I have used grpc in my projects and understand your questions about it. The first two questions can be answered via a quote from grpc.io followed by some elaboration.

- For me, another question that still remains why HTTP2 is not supported through browser APIs, to which I cannot find any documentation on.

- It looks like grpc-web is pretty well maintained and always adding a lot of language support, so that's something to keep an eye on... but as I understand it grpc-web is still built to operate over HTTP1.1?

It is currently impossible to implement the HTTP/2 gRPC spec3 in the browser, as there is simply no browser API with enough fine-grained control over the requests. For example: there is no way to force the use of HTTP/2, and even if there was, raw HTTP/2 frames are inaccessible in browsers. The gRPC-Web spec starts from the point of view of the HTTP/2 spec, and then defines the differences. quote reference

- I would love to start using gRPC, but am also concerned about the
cons that might come with it.

I puplished an story about gRpc. You should read. This can be helpful to understand gRPC.

I also want to talk about this topic. Why do you want to use gRPC? Is this about the speed of Http2 and gRPC? Is Http1.1 is old technology? Today, REST protocols work on Http1.1. If they start to use Http2.0, there won't be any changes to these interfaces. Also, REST is faster than gRPC if you don't work with streaming. gRPC has a better advantage when it comes to speed.

Below, I linked the supported types of RPC from GRPC-WEB

enter image description here