Blazor's Future: gRPC Is Key
Sanderson, who is credited with creating Blazor some 2-1/2 years ago, shed some light on its future in a presentation at the recent online .NET Conf that was titled, appropriately, "Focus on Blazor." His presentation, "Blazor Future Features," expands on previous Blazor prognostication guidance that came out of last fall's .NET Conf, where Daniel Roth discussed how Blazor's renderer -- currently targeting the web -- can be swapped out for other project types, such as Progressive Web Apps (PWAs), hybrid apps and desktop apps via Electron.
A complete example of another target -- native iOS and Android apps -- also arose from the latest conference and is detailed here.
But, as mentioned, Sanderson focused on gRPC, testing and the desktop.
gRPC is an open source remote procedure call system created at Google in 2015. It's being positioned as a replacement for Windows Communication Foundation (WFC), which is part of the old .NET Framework that didn't make the transition to .NET Core.
However, Sanderson demonstrated another purpose for gRPC: acting as a substitute for JSON. In the example FlightFinder app, Sanderson explained the advantages of using gRPC instead of using an HTTP client to post a JSON request to the server for flight data, which also comes back as JSON. One of the drawbacks to the JSON approach is worrying about the correctness of hard-coded URLs, he said.
"Another drawback to this form of data access is that the data that we're sending is very verbose because it's all in JSON format," Sanderson said. "So here you can see the payload that we're sending to the server. This is very robust text-based JSON data and the response that's coming back is also JSON data, which is not very efficient on the wire. So considering these two drawbacks -- the fact that we have to hard-code lots of assumptions about URLs and things and that it's not very efficient on the wire -- you might think, 'well could there be a more efficient, more modern alternative to sending JSON over these unstructured URLs?' and the answer to that is yes, there's lots of other alternatives to that and one of them that's been gaining a lot of traction recently is gRPC."
While gRPC traditionally can't be used from within web browsers, such functionality is allowed via gRPC-Web, whose site says, "gRPC-Web clients connect to gRPC services via a special gateway proxy: the current version of the library uses Envoy by default, in which gRPC-Web support is built-in."
After demonstrating how the FlightFinder app works with gRPC instead of JSON, Sanderson said, "It was absolutely trivial to call this method on the server from the client with this very efficient binary data on the wire, and that's the cool thing about using gRPC."
Developers wanting to learn more about using gRPC in Blazor/ASP.NET Core are in luck because that happens to be the current focus of Visual Studio Magazine writer Peter Vogel. Here are some recent articles he's penned so far.
After finishing with gRPC, Sanderson moved on to testing Blazor components, explaining how the team is exploring an alternative to the two traditional ways of testing: unit tests, which are fast and robust, but low-level, and browser automation, which is high-level, but slow and not very reliable. The team is looking for way to create a new way of testing that takes the best from each approach, as depicted here:
"So that's something that we've been working on, producing a little proof of concept for," said Sanderson, who went on to demo exactly that.
Yet another take-the-best-of-both-worlds approach is being followed with installable desktop apps. Here, the two choices using Blazor are Progressive Web Apps (PWAs), which are lightweight but not native and can't access the OS, and Electron, which has native code and OS access, but is heavy to download and run:
The solution is what Sanderson calls WebWindow, which he used to again modify the FlightFinder app to a Mac desktop app. WebWindow is described here by Sanderson as "a cross-platform webview library for .NET Core." In that post, Sanderson says, "It's like Electron, but without bundling Node.js or Chromium, and without most of the the APIs."
Developers can learn more by watching a video of Sanderson's presentation. Other videos available from the .NET Conf discuss routing, creating a great UX, state management and many more. Also, the FlightFinder app's source code is available on GitHub.
David Ramel is an editor and writer for Converge360.