Here is the syntax for calling taken based web api in Blazor server or webassembly.
using MyFleetApp.Data.Model;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
namespace MyFleetApp.Data.Service
{
public class InvoiceSearchService : IInvoiceSerach
{
private readonly HttpClient httpClient;
public InvoiceSearchService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
public async Task<Rootobject> GetInvoices(Rootobject objParameter)
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", objParameter.token);
var result = await httpClient.PostAsJsonAsync<Rootobject>("Web API URL will be here", objParameter);
Rootobject objInvoice = new Rootobject();
if (result.IsSuccessStatusCode)
{
objInvoice = await result.Content.ReadFromJsonAsync<Rootobject>();
}
return objInvoice;
}
}
}