Q:

How do you send an HTTP GET request using HttpClient in Blazor?

0

This code will help you to understand how to send an HTTP GET request using HttpClient in Blazor.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

An HTTP GET request can be sent to get a resource from the API server using the GetJsonAsync() method provided by the HttpClient class.

CSHTML

@page "/employee"
@inject HttpClient Http

.. .. .. .. .. .. 
.. .. .. .. .. ..

@code {
        Employee[] empList;

        protected override async Task OnInitializedAsync()
        {
            empList = await Http.GetJsonAsync<Employee[]>("/api/Employee/Index");
        }
}

WEB API

[HttpGet]
[Route("api/Employee/Index")]
public IEnumerable<Employee> Index()
{
    return employee.GetAllEmployees();
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now