As I’m currently evaluating Blazor (Server) I made a simple POC application In VS2019 (Version 16.3.8) for ordering pizzas. I created a Blazor Server App which get’s it’s data from a Web API Core 3.0 Project, nothing fency, getting data at startup in the Index razor page is implemented as next:
And the service which hides the external API-call is implemented as next:
So I’m using the regular GetStringAsync() method on the created http client instance which returns The requested data as a json-string which is finally deserialized to the required object-type. But, unfortunately I can NOT use the GetJsonAsync() method here, as shown from the GitHub samples which can be found here:
https://github.com/software-architects/learn-blazor/tree/master/samples/RestApi
After searching for a while, I came through next site :
https://learn-blazor.com/architecture/rest-api
which explained me I had to use the “HttpClientJsonExtensions”, as mentioned in next fragment from the site:
So, after downloading the samples and having a quick look at the “RestApi.Client” project (which contains the WebAssembly hosted App), I see next referenced dependencies:
Which has (apparently) the extension method on the “Http” class for using GetJsonAsync() method from within the Client App.
So, my question is quit obvious, how can I have the same behavior in my Blazor Server based app, because there are no Microsoft.AspNetCore.Blazor dependencies in my Blazor Server based app, as you can see next:
And because my PizzaMenuService lives in the “Services” folder of my Blazor Server app and makes the call to the Rest API (as shown at the beginning of my request), it doesn’t have the extension method for executing GetJsonAsync() … How can this be achieved then on a Blazor Server based app ?
Thx for any response ! 😊
Emmanuel Nuyttens.





