I have installed the package by adding the latest package ref.
from https://www.nuget.org/packages/Microsoft.AspNetCore.Blazor.HttpClient/
But still i am unable to find the desired function like .. Client.GetJsonAsync
Can you please help me out if i am missing something? Thanks.
I am trying out here but cant.
public async Task<User> GetUser(string Id)
{
HttpClient client = new HttpClient();
var user = await client.GetJsonAsync($"{BaseUrl}Get-User/{Id}");
return JsonConvert.DeserializeObject<User>(user);
}
1. Add nuget package System.Net.Http.Json
2. Add this namespace in using System.Net.Http.Json
Nothing worked for me and nobody pointing at this clearly.
These extension methods exists in System.Net.Http.Json
namespace.
To use these methods you need to first add this package System.Net.Http.Json.
Then add this System.Net.Http.Json
namespace in using.
Only then json extension methods will appear with HttpClient object.
The method signature is the following:
public static async Task<T> GetJsonAsync<T>(this HttpClient httpClient, string requestUri);
So it is a generic method and you will have to include the type argument in the call.
In your case, this should look like this:
HttpClient client = new HttpClient();
var user = await client.GetJsonAsync<User>($"{BaseUrl}Get-User/{Id}");
This will already deserialize the JSON response to the User
type.
Note that you will need a using for the Microsoft.AspNetCore.Components
namespace in order for this extension method to appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With