Call REST API from ASP NET Core Blazor

preview_player
Показать описание
How to call and consume a REST API from ASP.NET Core Blazor application.

Text Article and Slides

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.

Blazor tutorial for beginners

Blazor Blog

Angular, JavaScript, jQuery, Dot Net & SQL Playlists

Let's gift education together
Рекомендации по теме
Комментарии
Автор

I needed this so much, you saved me from a deadline. Thank you So Much

Alex-bctt
Автор

Great, I do it. Thank you very much, please keeping up

yyttommy
Автор

I really like your work arrangements .. just wondering why you didn't use generic repository and unit of work .. it's more usable

alihaydar
Автор

Thank you so much. I have a question.
what is the alternatives for namespace since this is in preview

zorigdavaag.
Автор

Here is a small piece of code to call the API. This is generic so that we don't need to write the code again and again.

//THE INTERFACE
public interface IApiHandler
{
Task<T> GetAsync<T>(string url);
}

//THE IMPLEMENTATION TO CALL THE API
public class ApiHandler : IApiHandler
{
private readonly HttpClient _httpClient;

public ApiHandler(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<T> GetAsync<T>(string url)
{
return await
}

//TODO
//CODE FOR POST, PUT, DELETE CAN BE ADDED
}

//THE STARTUP CLASS
services.AddHttpClient<IApiHandler, ApiHandler>(client =>
{
});


//CALLING THE SERVICE(ApiHandler)
public class EmployeeListBase : ComponentBase
{
[Inject]
private IApiHandler _apiHandler { get; set; }

public IEnumerable<Employee> Employees { get; set; }

protected override async Task OnInitializedAsync()
{
Employees = await
}
}

jayantlalguru
Автор

Thank you. I would like to let you know that while testing on creating a new employee, I happened to find a false error of email address already exists for a new client and new email address, I ran the application in debug mode and postman for this very lesson. It would be nice to give an explanation as to why that happened as I was expecting to commit the new employee without any problem.

nichodemusomedo
Автор

NuGet package is not available to download, however I searched in google and downloaded that package of version 3.2.0-preview3.20168.3 depricated.
it is working to extract data from database using EFC and using API, but it is not working for Blazor app EmployeeListDetails :Shall you please provide that NuGet package.

kalapalababurao
Автор

please sir what do you think about using Refit and create an SDK to consume the API?

sabrinadiaf
Автор

Thanks Venkat, great job. I've been doing my head in trying to get this very thing working and here it all is in one tidy package. When the product is deployed the hard-coded base URL will not work, how would you set that up so it can be different and automatically set in each deployment environment please?

aikidoshi
Автор

Thanks a lot for all your great tutorials.
about this video - in 3:20 you are talking about Startup.cs file. but in web assembly project, there is just Program.cs file.

ernanmaisels
Автор

Thank you but i tried to use a generic service instead (ApiService) which implement (IApiService) then i tried to register it the same way you did but that didn't work can you please tell me a hint how to achieve this please.

EngDuraid
Автор

Sir may i ask, why you are using Httpclientfactory instead of signalr to connect to the API? Like what the browser does to connect to blazor server? thank you in advance.😊😊

rainron
Автор

I get it "An unhandled exception occurred while processing the request.
JsonReaderException: '<' is an invalid start of a value. LineNumber: 1 | BytePositionInLine: 0" error :/ how fix I try on Net Core 3 ant Net 5 via your video tutorial but I can run

Beji-boy
Автор

Is somewhere avaiable source code? I missed something and i would like to compare?

HRJosef
Автор

can someone please explain to me why he uses services to call rest api when he already have a class library, when should we use class library or services

pylvr
Автор

I did a blunder while posting in postman, I posted it in different format and not in JSON. I cannot load the details on that page, but I am able to retrieve employees/1 or employees/2 except for the one that I wrongly posted. I do not know how to delete it as I tried to delete it, it showed some error. Anyone help me with this

ronswanson
Автор

thanks for you
how can i call the REST API in xamarin forms

moawadabdelbasset
Автор

Sir can i get any help in vb.net chats formation with chart.js and sql

vinitmishra
Автор

I canot call api in employee service to consume any one can help?

rohhappyness
Автор

The method "OnInitializedAsync" in the class "EmployeeListBase" of the Web project is called automatically twice when i run the project! Why?

stefanvettiger