Reputation: 781
One thing that I like about Blazor WebAssembly is the possibility to share a class between the client and the .Net Core server. Let's make this example where there are 3 prjs:
Both Blazor and ASP.Net prjs reference the Class Prj. Imagine the classic Blazor demo, we can say that WeatherForecast is defined in the Class prj, in the ASP.Net prj there's an API method that retrieves data from DB and fill the WeatherForecast array, serialize it to pass it to the Blazor client which deserialize it again into a WeatherForecast array.
I wonder if there is a more efficient way to transfer data between the api and the blazor app.
Serializing it to a json and then deserializing it back to a WeatherForecast array doesn't sound like the best option. Is there a way to transfer the data in another format, maybe a compressed binary that should be lighter and faster to transfer than a Json?
Upvotes: 0
Views: 746
Reputation: 1667
As @DavidG mentioned you might want to take a look at gRPC.
This video shows a good introduction to it in Blazor between client and server: https://www.youtube.com/watch?v=ess1SBBMmhg
Starting from 5:30.
gRPC for Blazor WebAssembly (client-side) is not yet in preview (a future feature as the video show). But will be after the May GA release of Blazor WebAssembly. So expected to be GA in .NET 5 and in preview after May.
With that being said, you can still make it work between client and server in other ways
gRPC requires HTTP/2
Upvotes: 2