Post Top Ad

Asp.Net Core Mvc

Blazor

Post Top Ad



Calling REST API ASP NET Core Blazor | WEB API

Developers who are used to writing C# code in ASP.NET will find it very simple to consume web APIs with Blazor. All the usual classes (e.g. System.Net.Http.HttpClient) and language constructs (e.g. async and await) are available. Therefore, reading data from a server and printing it in the console looks like this in Blazor.

@page "/"
@inject HttpClient Http

<button onclick=@(async () => await PrintWebApiResponse())>Print Web API Response</button>

@code{
    private async Task PrintWebApiResponse()
    {
        var response = await Http.GetStringAsync("baseUrl/api/Product/GetAll");
        Console.WriteLine(response);
    }
}

No comments:

Post a Comment

Post Top Ad