4 ms·
What's the advantage of using this over something like XMLHttpRequest?
by continuations 8y ago
What's the advantage of using this over something like XMLHttpRequest?
- darkhorn 8y agoXMLHttpRequest does not have a remote procedure call (RPC).
- continuations 8y agoI meant what's the advantage of using RPC instead of XMLHttpRequest to communicate with the server.
- skybrian 8y agoWell, XMLHttpRequest alone doesn't cover much so you're really comparing with HTTP requests combined with JSON and whatever you use to document your JSON API. The advantage of protobufs is basically static typing with backward-compatible serialization (you can add new fields), that's compatible with many server-side languages. It's honestly an awkward fit for web apps, though. Basic things are different, like int64's aren't native to JavaScript.
- timdorr 8y agoXHR is really just an HTTP client, despite the name. It doesn't enforce anything regarding inputs and outputs of an HTTP request. gRPC gives you guarantees on those inputs and outputs, along with a bunch of extra features. It's basically a layer on top of XHR.
- pcj-github 8y agogrpc-web indeed does use XMLHttpRequest internally to make the request to the server. Main advantage is type-safety of the overall communication protocol and some efficiency gains. Cannot be stated strongly enough how important compile-time type-safety guarantees between client and server is (particularly in a "microservices" environment where everything is disconnected at runtime); eliminates an entire class of bugs, frees developers to focus on more business-relevant tasks rather than worrying about serialization.