How to Utilize gRPC-Web From a Blazor WebAssembly Application
Its no secret by now that there has been a lot of excitement about gRPC recently in the .Net community. gRPC is a modern high-performance RPC (Remote Procedure Call) framework. It is based on HTTP/2, Protocol Buffers and other modern standard-based technologies. It is also an open standard and is supported by many programming languages, including .NET.
It is currently impossible to implement the gRPC HTTP/2 spec in the browser because there are no browser APIs with enough fine-grained control over requests. Well the good news is that gRPC-Web is here for the rescue!!!
gRPC-Web is a standardized protocol that solves this problem and makes gRPC usable in the browser. gRPC-Web brings many of gRPC’s great features, like small binary messages and contract-first APIs, to modern browser apps. In this post I will demonstrate consuming a gRPC-Web endpoint from within a Blazor WebAssembly application. Along the way I will also demonstrate how gRPC-Web can achieve more efficient payload sizes compared to Restful endpoints.
The source code is hosted on my Github repository which can be found here.
The Solution
The solution I provided includes three projects. The Blazor WebAssembly project is the front end which will consume both a gRPC-Web endpoint as well as Restful endpoint.