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

  • Visual Studio 2019 v16.7 Ships with Better Git Integration

    Better GitHub integration and other improvements highlight the new Visual Studio 2019 Version 16.7 and first preview of v16.8.

  • Visual Studio Codespaces Private Preview Woos C++ Developers

    Microsoft announced a private preview of Visual Studio Codespaces, which eases the setup and use of cloud-powered development environments that can be used from anywhere for remote development and other scenarios, targeting C++ console app and library developers.

  • Data Prep for Machine Learning: Normalization

    Dr. James McCaffrey of Microsoft Research uses a full code sample and screenshots to show how to programmatically normalize numeric data for use in a machine learning system such as a deep neural network classifier or clustering algorithm.

  • Microsoft Intros Azure Well-Architected Framework Best Practices

    Taking a page from the Amazon Web Services (AWS) book on cloud computing platforms, Microsoft has introduced its own Azure Well-Architected Framework, providing a set of architecture best practices to help users build and deliver great solutions and improve the quality of cloud workloads.

  • Creating a Progressive Web App with Blazor WebAssembly

    Not surprisingly, it's dead easy to create an app in Blazor that runs outside of the browser window and (potentially) in an offline mode. Before you get carried away, though, there are some key design decisions to make.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events