Can I use gRpc as a replacement of SignalR for updating notification on client-side?
Asked Answered
S

3

8

I'm new to gRpc and now learning this tech

I'm wondering if gRpc can replace SignalR for updating notification bar on my client-side app (React). Is that the case? or should I keep using SignalR for this matter?

(I'm asking it just to make sure I understand the purpose of the gRpc tech, by few articles I read it's more a web API replacement and few others compare it to SignalR)

Thanks! y-me

Shaduf answered 4/4, 2020 at 12:6 Comment(0)
H
8

Assuming you meant browser-based clients, then NO you cannot use gRPC. The gRPC protocol relies on HTTP/2 framing and in particular the ability to send and receive HTTP trailers. While browser themselves can and do use HTTP/2, current browser APIs (XHR/Fetch) don't expose HTTP/2 semantics.

There is however an alternative protocol, gRPC-web, that supports a subset of gRPC functionality you can utilize from a browser-based application. Given that it is a different protocol, your server will need to support it or you will need to employ a proxy like Envoy that can translate gRPC-web calls to gRPC.

Hippy answered 15/4, 2020 at 19:23 Comment(0)
I
4

I can't answer your question has if it is usable for Server/Client communications, just offer some thoughts. SignalR is made for the purpose of real time communications between Client and Server because of it's adaptability, and gRPC by it's constraints (HTTP/2 and HTTPS) is more reserved for backend micro-services communications.

Interrelated answered 5/4, 2020 at 8:54 Comment(2)
Thank you for your reply @pedrolegold! I understand what you are saying in regarding the purpose of each of the technologies, but wondering if I can do something like: My browser calls my backend to GET data My backend is calling a local gRpc service and return stream (instead of single response) - if it's even possible :) If it does - I can basically implement gRpc push notification service - but I guess I aimed to high or to the wrong directionShaduf
I am using gRpc for chat application which works quite good. Grpc stream are for things which you want to put now on screen, so push notification is wrong approuch. Basically you would need some background gRpc stream all the time and same on server side. There are firebase services which does exacly thatHenotheism
S
1

Microsoft preferred to use SignalR for the Blazor app. They haven't used gRPC. I think this answered your question.

If your WebApp is built in React and if a request is making multiple API calls internally, then you can use a webapi on top of multiple gRPC services. Then your API will act as a wrapper for all the gRPC and the WebApp(React) will be free from gRPC calls.

Salesmanship answered 9/12, 2023 at 18:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.