News

Blazor's Future: gRPC Is Key

Blazor guru Steve Sanderson detailed what Microsoft is thinking about the future of the revolutionary project that enables .NET-based web development using C# instead of JavaScript, explaining how gRPC is key, along with a new way of testing and a scheme for installable desktop apps.

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

Blazor gRPC
[Click on image for larger view.] Blazor gRPC (source: Microsoft).

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:

Blazor Testing
[Click on image for larger view.] Blazor Testing (source: Microsoft).

"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:

Blazor Desktop
[Click on image for larger view.] Blazor Desktop (source: Microsoft).

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.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube