Call REST API from ASP NET Core Blazor

  Рет қаралды 69,734

kudvenkat

kudvenkat

Күн бұрын

Пікірлер: 111
@Alex-bc3tt
@Alex-bc3tt 4 жыл бұрын
I needed this so much, you saved me from a deadline. Thank you So Much
@jayantlalguru6780
@jayantlalguru6780 4 жыл бұрын
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 GetAsync(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 GetAsync(string url) { return await _httpClient.GetJsonAsync(url); } //TODO //CODE FOR POST, PUT, DELETE CAN BE ADDED } //THE STARTUP CLASS services.AddHttpClient(client => { client.BaseAddress = new Uri("localhost:44336/"); //ADD YOUR BASE URL INSIDE THE BRACKET }); //CALLING THE SERVICE(ApiHandler) public class EmployeeListBase : ComponentBase { [Inject] private IApiHandler _apiHandler { get; set; } public IEnumerable Employees { get; set; } protected override async Task OnInitializedAsync() { Employees = await _apiHandler.GetAsync("api/Employees/GetEmployees"); } }
@ernanmaisels
@ernanmaisels 4 жыл бұрын
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.
@Nynxxx
@Nynxxx 4 жыл бұрын
I am not sure if you needed anything clarified, but he did mention that this video series is just going to cover Blazor Server and not Blazor WASM.
@SupunNimantha
@SupunNimantha 3 жыл бұрын
same issue . have you resolved this ?
@ernanmaisels
@ernanmaisels 3 жыл бұрын
@@SupunNimantha Yes. just use the program.cs file and insert all your services on Main method. Good luck!
@SupunNimantha
@SupunNimantha 3 жыл бұрын
@@ernanmaisels yeah that worked. I had some services
@EduardoSantos-tr4gb
@EduardoSantos-tr4gb 2 жыл бұрын
And what about the localhost url u do something?
@cristians2976
@cristians2976 4 жыл бұрын
You are doing an excellent job
@BCLBlazorCollectionsLibrary
@BCLBlazorCollectionsLibrary 4 жыл бұрын
Exactly, I love his every blazor tutorial :)
@alihaydar3021
@alihaydar3021 4 жыл бұрын
I really like your work arrangements .. just wondering why you didn't use generic repository and unit of work .. it's more usable
@LetCode96666
@LetCode96666 4 жыл бұрын
Love this playlist!
@yyttommy2456
@yyttommy2456 Жыл бұрын
Great, I do it. Thank you very much, please keeping up
@eeveeadm8367
@eeveeadm8367 4 жыл бұрын
Thank You Sir. God Bless You.
@CCPony
@CCPony 4 жыл бұрын
I love the Venkat!
@AniketRamekar
@AniketRamekar 4 жыл бұрын
Very good tutorial Venkat. Thank you.
@kameshp68
@kameshp68 4 жыл бұрын
Nice presentation
@MegaxAT
@MegaxAT 2 жыл бұрын
a great video! thanks
@aikidoshi007
@aikidoshi007 4 жыл бұрын
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?
@AniketRamekar
@AniketRamekar 4 жыл бұрын
It depends based on how secure you want things to be. You can use appsettings.{Environment}.json files (link1), or go all out with app secrets (link2) link1:docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1 link2:docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows
@aikidoshi007
@aikidoshi007 4 жыл бұрын
@@AniketRamekar Thanks Aniket, sorry for the late response, I've been so busy, now getting back to Blazor.
@Rajeshsingh-ws5th
@Rajeshsingh-ws5th 4 жыл бұрын
Great Venkat.
@sathishkomakul
@sathishkomakul 4 жыл бұрын
Plz start tutorial of C# WPF
@zorigdavaag.8354
@zorigdavaag.8354 4 жыл бұрын
Thank you so much. I have a question. what is the alternatives for Microsoft.AspNetCore.Components namespace since this is in preview
@kalapalababurao1788
@kalapalababurao1788 3 жыл бұрын
Microsoft.AspNetCore.Blazor.HttpClient 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.
@keshavprasad
@keshavprasad Жыл бұрын
I am getting the same problem. Did you find any alternate solution for this?
@nichodemusomedo4
@nichodemusomedo4 4 жыл бұрын
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.
@jamaissans2377
@jamaissans2377 4 жыл бұрын
Thank you Mr.
@moawadabdelbasset9896
@moawadabdelbasset9896 4 жыл бұрын
thanks for you how can i call the REST API in xamarin forms
@AniketRamekar
@AniketRamekar 4 жыл бұрын
use HttpClient, refer: docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/rest
@rainron2664
@rainron2664 3 жыл бұрын
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.😊😊
@HRJosef
@HRJosef 2 жыл бұрын
Is somewhere avaiable source code? I missed something and i would like to compare?
@sabrinadiaf3230
@sabrinadiaf3230 4 жыл бұрын
please sir what do you think about using Refit and create an SDK to consume the API?
@EngDuraid
@EngDuraid 4 жыл бұрын
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.
@Beji-boy
@Beji-boy 3 жыл бұрын
I get it "An unhandled exception occurred while processing the request. JsonReaderException: '
@mozaherhossain1036
@mozaherhossain1036 4 жыл бұрын
I got an Error while call rest api in blazor. The error is -> "AuthenticationException: The remote certificate is invalid according to the validation procedure. System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception) HttpRequestException: The SSL connection could not be established, see inner exception. System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)". What should I do, please suggest me. Thank you...
@Desperate4Freedom.
@Desperate4Freedom. Жыл бұрын
Reinstall windows .
@stefanvettiger6308
@stefanvettiger6308 4 жыл бұрын
The method "OnInitializedAsync" in the class "EmployeeListBase" of the Web project is called automatically twice when i run the project! Why?
@ArpitSharma-g1b
@ArpitSharma-g1b 9 ай бұрын
search on stackoverflow
@EnriqueElcamel
@EnriqueElcamel 2 жыл бұрын
Hello, I'm having this weird error "System.Text.Json.JsonException: '
@pylvr8021
@pylvr8021 4 жыл бұрын
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
@ronswanson9635
@ronswanson9635 4 жыл бұрын
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
@ManuelHernandez-vi1it
@ManuelHernandez-vi1it 4 жыл бұрын
I am getting this issue : SocketException: An existing connection was forcibly closed by the remote host. Unknown location IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) HttpRequestException: The SSL connection could not be established, see inner exception. System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
@amer-ik7jj
@amer-ik7jj 4 жыл бұрын
An unhandled exception occurred while processing the request. AuthenticationException: The remote certificate is invalid according to the validation procedure. System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception) HttpRequestException: The SSL connection could not be established, see inner exception. System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
@amer-ik7jj
@amer-ik7jj 4 жыл бұрын
services.AddHttpClient(client => { client.BaseAddress = new Uri("localhost:44330/"); }) .ConfigurePrimaryHttpMessageHandler(sp => new HttpClientHandler { AllowAutoRedirect = false, ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true, SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 }); this solve problem
@Desperate4Freedom.
@Desperate4Freedom. Жыл бұрын
Reinstall windows .
@gulshan803
@gulshan803 3 жыл бұрын
Hi, i am facing this "The remote certificate is invalid according to the validation procedure. " issue while consuming rest API on "return await httpclient.getjsonasync(Employee[])("api/employee")". plz help me for the same...
@Desperate4Freedom.
@Desperate4Freedom. Жыл бұрын
Reinstall windows .
@mytrolls5866
@mytrolls5866 Жыл бұрын
why again server? already if we have web app very confusing please clear
@rohhappyness7297
@rohhappyness7297 4 жыл бұрын
I canot call api in employee service to consume any one can help?
@siddharthsharma2791
@siddharthsharma2791 3 жыл бұрын
Sir can you Suggest me how can i use web Api in Razor pages in this way
@vinitmishra9337
@vinitmishra9337 4 жыл бұрын
Sir can i get any help in vb.net chats formation with chart.js and sql
@Rajeshsingh-ws5th
@Rajeshsingh-ws5th 4 жыл бұрын
Most of the time, my seniors (some of them worked with Microsoft as well) suggested me not to use EF in our project. If this is true, why so?
@vladnik8115
@vladnik8115 4 жыл бұрын
What do they offer to use instead of EF ? (write EF by yourself! :) )
@chezchezchezchez
@chezchezchezchez 4 жыл бұрын
vlad nik dapper and SimpleCRUD. Your welcome! 👊🏻
@vladnik8115
@vladnik8115 4 жыл бұрын
@@chezchezchezchez How will you work with multiple related tables with a dapper? Can you give a link to examples?
@renusai23
@renusai23 Жыл бұрын
hi, i am getting data not retrieved server error 500
@njokuiyke01
@njokuiyke01 4 жыл бұрын
please who can help with this error: JsonException: '
@stefanvettiger6308
@stefanvettiger6308 4 жыл бұрын
This is because you get an error response instead of the real answer. An error response is in XML format an always starts with a '
@ranja6793
@ranja6793 4 жыл бұрын
I have the same error. Did you solved it?
@ranja6793
@ranja6793 4 жыл бұрын
I found out the problem: services.AddHttpClient(client => { // BaseAddress where the uri is available ! client.BaseAddress = new Uri("localhost:44338/"); // Api baseadress. this is the corrent uri //client.BaseAddress = new Uri("localhost:44385/"); // server baseadress. this leads to the error });
@tamasballai8703
@tamasballai8703 3 жыл бұрын
@@ranja6793 I've met with the same issue. Instead of the Api's port number I've given the Web's port number. Thank you so much for this comment, my problem has been solved.
@EnriqueElcamel
@EnriqueElcamel 2 жыл бұрын
@@tamasballai8703 can you please elaborate this i dont understand. Thank you
@Rajeshsingh-ws5th
@Rajeshsingh-ws5th 4 жыл бұрын
take care of your health due to covid-19
@maxsoftwaregraphics5714
@maxsoftwaregraphics5714 4 жыл бұрын
Dear sir null value is showing
@maxsoftwaregraphics5714
@maxsoftwaregraphics5714 4 жыл бұрын
Please helps me
@hughcoleman9400
@hughcoleman9400 4 жыл бұрын
@@maxsoftwaregraphics5714 Do you have same issue as discussed by Vivek a month ago, if so I don't understand solution either.
@hughcoleman9400
@hughcoleman9400 4 жыл бұрын
In my case it was because in my live version I had not included the code explained in part 8, Loading indicator explained reason for error
@rajushahi5089
@rajushahi5089 4 жыл бұрын
Authentication Exception: The remote certificate is invalid according to the validation procedure.
@ajanyhc
@ajanyhc 4 жыл бұрын
issue the following command: dotnet dev-certs https --trust
@stancyvincent7550
@stancyvincent7550 2 жыл бұрын
Where to use that command
@mainframehardtutorials8441
@mainframehardtutorials8441 4 жыл бұрын
Can we directly call database information into the Blazor App without any Api
@Nynxxx
@Nynxxx 4 жыл бұрын
You can, but it makes your app not scalable assuming that at some point you may want to switch to Blazor WASM. EDIT: Also, creating an API to call from can make it easier to implement new apps that aren't able to talk directly to the database, such as a mobile app that also wants to use the database, I am using xamarin to make an app, and we must have an API since it is not able to directly access the database.
@aussieraver7182
@aussieraver7182 2 жыл бұрын
6:59
@wassollderscheiss33
@wassollderscheiss33 3 жыл бұрын
I run into CORS problems. Meh
@wassollderscheiss33
@wassollderscheiss33 3 жыл бұрын
Had to do services.AddCors() in ConfigureServices(...) of WebApi project and app.UseCors(a => a.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().SetIsOriginAllowed(b => true)) in Configure(...)
@pankajcodesdot490
@pankajcodesdot490 2 жыл бұрын
Install-Package Microsoft.AspNetCore.Blazor.HttpClient -Version 3.2.0-preview3.20168.3 :- command
@k.divyaswarnkar5975
@k.divyaswarnkar5975 2 жыл бұрын
it is not available in nuget package manager can you please suggest how could i download ?
Blazor route parameters
10:21
kudvenkat
Рет қаралды 37 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 294 М.
Repository Pattern in ASP.NET Core REST API
11:12
kudvenkat
Рет қаралды 62 М.
ASP NET Core REST API get list of resources
9:47
kudvenkat
Рет қаралды 50 М.
Blazor Tutorial : Call REST API | CRUD Methods - EP10
20:54
CuriousDrive: Solve Coding Problems & Win Prizes!
Рет қаралды 32 М.
Blazor Form Creation: Effortless User Interaction for Web Apps
18:58
How to CALL POST API in C#! - THIS EASY!
14:15
tutorialsEU - C#
Рет қаралды 83 М.
ASP NET Core blazor hosting models
11:05
kudvenkat
Рет қаралды 132 М.
SEC000: Securing Blazor & Web APIs with AAD
30:25
Hassan Habib
Рет қаралды 9 М.
Search in ASP NET Core REST API
7:56
kudvenkat
Рет қаралды 35 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН