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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube