Still churning out new videos and immediately responding to comments from 3-year old videos :-) You're a credit to the community! Thanks for the videos and keep up the good work.
I have watched a few videos about calling API's. And I originally skipped this one because of the length, and I was so anxious to get started. After taking the time to watch it, I regret skipping over it. This video was so informative, and Tim really has a way of explaining everything very thoroughly. I am now a fan, and will be watching as many of your videos as possible. Thank you for taking the time to create these videos.
0:00 - Intro 1:00 - Demo application walk-through 4:09 - Setting up API calling: WebApi.Client and Newtonsoft.json NuGet references 6:02 - Setting up API calling: HttpClient 13:48 - Setting up API calling: API calls 19:14 - Setting up API calling: Reading and working with json data 28:18 - Loading image in WPF (form a website) 35:29 - Adding events in WPF application: wiring up action buttons 39:40 - Note on information Cashing 42:55 - Sunrise-sunset API: Nested json objects, API calls, WPF events, displaying information 51:56 - Loading other WPF forms from MainWindow 53:38 - Summary and concluding remarks
As a newbie to coding in general i appreciate the advice on the comic model. Just specifying the properties you need is golden nuggets. I’m always like ‘give me all the things magical internet box’ and I’ll figure out what I need, whilst my program grinds to a halt. Thank you Tim Corey for knowing what I need before I do.
I've been confused about API and integrating with C#, watched various videos about this subject and was still lost, your explanation has made it more clear. Thanks for your tutorials - looking forward to the continued courses.
I wondered how to connect to a web API for a long time. I sought out for the resolution for a long time and I couldn't understand anything until I've watched this video. Thank you a lot, sir.
I am probably a crappy starting up programmer who rarely subscribes to channels and rarely ever likes videos. For you I make an exception, this video was super helpful and this kind of content is rarely ever free. Thank you and God Bless the beard.
Thank you, Tim for pouring down all the information ( as much as you could ) from your heart and not holding anything back!!!! I'm feeling lucky to got stumbled upon this video amongst plethora of content out there!!!! Looking forward to learn new things about programming/coding/web development!! THANK YOU SIR!
Did this in generics because of knowledge from your other video about generics. Thank you, always happy to take a challenge when you suggest something extra.
Tim, Great tutorial. I would recommend anyone watching this to watch it all the way through. This really simplified everything I seen online. Too many people were making this really complicated but you solved that. I was originally looking for a tutorial on just getting and using data from a REST Api, after that was going to review getting images from that Api and displaying them in the app and then cycling from page to page. Tim I would recommend a different title on this video though which is why I went down the rabbit trail looking at other videos first. "C# WPF XAML REST API Tutorial - Examples, Best Practices, Memory Management, and Pitfalls" Though I have been programming for 20 years I am new to C# and I know ASP.NET uses C# and there is a difference between WPF XAML and Forms - hence my I suggest adding in those other 2 to the title. I subscribed and look forward to lots more videos.
I don’t really comment often but I just want to say thank you so much. You have been a really big help on a side project I’m working on and you explained everything so well!
Since i got stuck with this problem, it might be helpful to other beginners : if you are using an API that requests a simple token identification, pass the token as a header, not in the uri, as such: APIClient.DefaultRequestHeaders.Add("Authorization", "YourTokenHere");
Thank you Sir. Can you please do a video on serialization and deserialization in C# may be considering a wpf datagrid serialized into XML. I found many examples, but when you explain it will be complete for sure
At 23:47 ReadAsAsync cannot be found, in fact, I can't find any extension methods. When I type in ReadAsAsync it says 'HttpContent' does not contain a defnition for ReadAsAsync. I've downloaded your code, and I can't find what I did wrong . EDIT: the mircosoft web api nuget package was not installed for some reason
Hey tim, are you planning on doing a video about hosting a mock of an api with predetermined responses? If not, do you have any video / guide you might recommend?
Hi tim, another question: what do you think of the term "Full Stack Developer"? Do you consider yourself more "back-end" oriented, "front-end" oriented, or both?
I'm definitely a full stack developer. I can (and do) create user interfaces and I can/do create data access as well as everything in between. As far as what I feel about the term, I think it is fairly descriptive. Sure, usually people can do both but it is very common to specialize in one side or the other. The larger your company/team is, the more likely it is that you will specialize in one area. You get really good in that area and you may even let your other skills fade a bit (or you just don't keep up with the newest changes).
Firstly, i would like to say thank you for everything you are doing on here. you are a legend. Secondly, can you explain why you have chosen xaml over windows form, could the same outcome be achieved in both?
One more thing: I had to add this line: System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; to the InitializeClient() of the ApiClient. If not I was getting a HttpRequestException: "The request was aborted: Could not create SSL/TLS secure channel."
Hi, I am writing an application that will continuously run on a server to make a call to an API every hour. At what point should I enter the API key. Should this be done inside the InitializeClient void or will cause security issues having this open continuously?
Trying to cover authentication is tough because everyone does it differently. Usually the API documents how to do that. As for caching, I'll be covering that in a future video.
Tim, I need to tankyou, your classes are great, you have one of the bests teaching aproach I've ever seen. Keep this way, you are helping a lot of people. Tanks again, god bless!!
Hi, could not find an answer on the internet, so maybe you will help me. I heard that there is a new way of calling an API without NuGet packages. It already works without Newtonsoft but ReadAsAsync only exists in the NuGet package. If you know the answer, can you point me in the right direction?
Okay done. If somebody has the same question, I did it using System.Text.Json and this helped me: www.pmichaels.net/2020/02/22/my-object-wont-deserialise-using-system-text-json/
ohhh thank you soo much! i made a weather program with a console app. it did run succsessfully, but i didn't understand how the properties worked. this video helped me understand it! :)
Hi Tim - what made you want to use a static method for the instantiation of the ApiHelper.ApiClient instead of via constructor? What I typically do is create a customized httpClient in a class that inherits from HttpClient. This way I can use DI to bring it in. Any thoughts on this?
can u make video how to parallel use api or post/get requests imagine i need to registrate accounts but nor one by one how to registrate accounts for example in 10 tasks each of them have different proxy, coockie and exc. or can you give link with any example of it ty for ur staff
I'll put that on the list for a follow-up video. In the meantime, you could probably do a parallel.foreach like I demonstrated in my Advanced Async video.
Hi Tim! In your video you mention building a generic Api data processor. Have you made or are you planning on making a course on that subject? ...and thank you for your videos!!
Hi Tim, does the values of LoadSunInformation update for each day? In addition does this tutorial include constantly updating information when the JSON or website file is update?
Hi Tim, could you please briefly explain to me what's the difference between making the ApiHelper class static and then calling the InitializeClient() method vs. making a non-static class and registering it as Singleton service in the Startup.cs (as services.AddSingleton() ...) Thanks!
In this case, it was because we weren't using dependency injection (this is a .NET Framework project so it doesn't have DI built-in like ASP.NET Core projects do). If I had DI available and this were a "real" app, I would implement the class as a singleton, since it allows for constructors, interfaces, and more.
Hi Tim, I followed this tutorial but the return type of the api is inside an array like this [{"kenteken":"83MHKP","brandstof_volgnummer":"1","brandstof_omschrijving":"Benzine","geluidsniveau_rijdend":"74","geluidsniveau_stationair":"93","milieuklasse_eg_goedkeuring_licht":"(EU) 134/2014","nettomaximumvermogen":"84.60","toerental_geluidsniveau":"5000"}]. Now I get an error when I run this code: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in System.Private.CoreLib.dll. Do you know how I could solve this error?
My guess is that your model you are trying to map to is not correct. Are you telling Newtonsoft that it is a List or just T? You need to say it is a List since it is an array.
Thanks for this wonderful video, i had to use 1.25 speed :D . I added a buffer to store existing calls results ,a spinner to show Ajax call in progress and a button to read out ALT text :D BTW, this Comics are kinda fun to read
Hi Tim. Is there a pattern available to handle APIs that work based off a Request/Response with Events? To be more clear: The API accepts a Request Type and a Request ID, and raises an event when the request is fulfilled, referencing the Request ID. My first take on this involved a lot of globals to manage state and flow and all sorts of code in the event handlers, and having not looked at it months, I'm lost as to where I was going with it.
Excellent tutorial, now understood how it works, but was wondering if you requesting any files or PDF through API? what sort of properties would we use to display files instead of text?
Yep. You would have less to do. You would do the HttpClient initialization in dependency injection and pass that into the ApiHelper class. We do that in the TimCo Retail Manager series.
Pretty much. If you have authentication on your API, you will need to do more. The TimCo Retail Manager series ( th-cam.com/play/PLLWMQd6PeGY0bEMxObA6dtYXuJOGfxSPx.html ) creates an API with authentication and connects to it using WPF. That would be a good example to follow.
Pretty much. I usually save the data to a small database (SQLite, MongoDB, etc.) and the images to disk in a temp folder. I also save the API call parameters or the entire call to the database too. When a call comes in for the exact same data, I go to my database instead. You just need to know how long to cache it for based upon the resource. For example, sunrise/sunset data doesn't change for the same exact data. I could keep that forever. Stock market data changes a LOT so I might only cache the data for 15 minutes (if it was an informational application) or not at all (if it was an investing application).
Check out the TimCo Retail Manager series. Right now we are wiring a Blazor WebAssembly application to an API that has authentication with bearer tokens which include role authorizations. We also wired up a WPF project to the same API.
Good video. I don't know why they have to make these packages so complicated. I'm trying to build a simple API client that sends a JSON payload with custom HTTP headers used for authentication and expects a JSON response on success or failure. It doesn't need to be asynchronous because I don't want the application doing anything else while the call is out or until the call times out. The JSON is being handled with Newtonsoft's Json.net. It just seems very difficult to find human readable documentation about system.net.http that shows how to do such a thing.
I think part of it is that you are expecting to do something that isn't simple. That list of requirements entails quite a few things. Dropping async isn't really possible/necessary since the web is, by default, asynchronous. This video shows you how to connect easily to an API and get the data you need.
@@IAmTimCorey Interestingly enough, after posting this comment I decided to try and decipher Microsoft's official docs on HttpClient and was able to get the skeleton functions up and running. It actually wasn't that difficult once I used my secret decoder ring to translate MS speak to plain English. Plus, I planned out exactly what my app was going to do before I wrote a single line of code, as you mentioned in one of your videos, so I knew which functions fit my requirements after a little bit of reading. BTW, I know your courses were made a while back but your videos have been instrumental in helping me get this app up and running. I'm a photographer, not a software developer so this has been one HUGE learning experience in the month since I started learning C#. Thanks for putting all these videos out there. I'm definitely considering purchasing your course, to say thank you.
Agreed, .NET's existing libraries are verbose and the documentation is hard to digest. From my personal l can highly recommend any of these free, open-source NuGet packages. These are all well maintained & make for a much better developer experience: 1. ServiceStack.Text( 1k GitHub stars, 7m Nuget downloads) - fast light and resilient. 2. RestSharp (6k GitHub stars, 23m Nuget Downloads) - Simple REST and HTTP API Client 3. Flurl (1.7k GitHub stars, 3m Nuget Downloads) - a fluent, portable, testable HTTP client library
Great video. One question: What if a json response from an api contains an array? How do you map that to properties? For example: "weather": [ { "id": 804, "main": "Clouds", "description": "overcast clouds", "icon": "04n" } ]
In this specific example, you could have this property: public List Weather { get; set; } You can also paste the json into C# using the Paste Special option to see how the class structure would work.
Hi Tim. Thanks for all the great content. This may be one for the back burner or a separate resources video related to consuming rest APIs. There seem to be a wide variety of tutorial videos that relate to consuming a single endpoint, but not really anything that I've been able to find in terms of completing an "object graph". For example, if there's a theroetical API with a single product endpoint that can be retrieved via simple id key and that product has a number of related lookup id's for other related objects with separate endpoints - what would the options be in retrieving those or keeping them either cached or in memory to improve the efficiency of requests? Many thanks
Hi, When running the program at 33:46. Am getting the error “Program does not contain a static “Main” method suitable for an entry point” - what a wrong with my code? Thank you for the help’
It sounds like you are trying to start your class library instead of your API project. Right-click on your API project and select "Set as startup project".
Hello Tim, I have the following question: In this video you have the controller that actually does the job. I saw however that on your TimCo retail series you have a controller that defines what should get post etc actually do.. I tried to extend your video here to get data from another api without success. The notions are not so clear yet (and I haven't finished your timCo retail series videos on API). So in its documentation (the pi i want to use) says for example: the end point url is blabla ( no free advertising :P). If you want to get a random fact from the endpoint go for GET /facts/random. I build exactly the request as you did here, and I expected that a url blabla/facts/random would do the trick. It does nothing though ( SunInfo = null). What am I missing? Were am I mistaken?
Try calling the API in Postman. Make sure it returns a value that you expect. Then make sure your model you are capturing it into is laid out correctly.
This video covered exactly what I've been trying to figure out. Every thing I got from SO was basically the same code snippet a million times and wasn't helpful.
Thank you! I was just making similar things in my project, trying to figure out the best practices. GET is cool, but I also need to POST things and I guess I have found them with title: Posting Sales Data to an API - A TimCo Retail Manager Video. Also looking forward watching all the Role management videos, cause I also implemented the default web api authorization using /Token. So far I was just doing manual service calls with Postman, to make users, roles, and adding roles to users :D
Hi, I currently trying to code the first part, with the display of a comic on the windows, but I get this exception : "httprequestexception was unhandled by user code", with the additional information : "An error occurred while sending the request". This exception is linked to the line "await LoadImage();" in the main windows, or it is linked to the line "using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))" of the comicProcessor. I tried also to test your code but I get the same exception. I use Visual Studio 2015, can it be the problem?
ok, so the thing here is that the wording of VS 2015 is missing an important point and I was not able to solve this, so I installed VS 2019, same error, however, there was additional error message, and I managed to find a solution, you have to add this under the "private async Task LoadImage(int imageNumber = 0)" ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; If this doesn't work, try this: ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; For more info: stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
Do you also have a video on how to make proper post calls using this same style? I would like to know what the proper way of posting data to a service that would send it to a database. You don't exactly want sensitive data being visible on the web. It would also be nice to look at this in the way of registering a user and logging in since it's a real life and practical example.
I do not yet but it is coming. The key is that I have to pick one API for uploading. In this case, I will make my own but what I do in that won't be the same as what you do with other APIs. As for sensitive data, if you POST data and you are using HTTPS, you are protected (or at least 99.9% protected).
hi Tim, you mentioned authentication, why not cover basic authentication, token-based, and the one that uses grant type = client_credentials (oauth 2.0), that would be awesome! thanks
@@IAmTimCorey ya man please do , i want to use for trello lets say api.trello.com/1/boards/?key=0123token=123name={name}' like i put my key i put my token then in the name what do i put when i put the name lets say like this -> its not working This is to create a board: api.trello.com/1/boards/?key=0123token=123name=yolo Then it says : Cannot GET /1/boards/?key developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-post Do i need to do something else before trying to put the name et.c
You can add this to your code if you're stuck. I'm not sure if this is the correct way but it works. replace bas64tokenhere with your base64 encoded username:password // ApiHelper.cs ApiClient.DefaultRequestHeaders.Accept.Clear(); ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ApiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "base64tokenhere");
Yet another one of your videos that addresses something I am working on, your channel is great man thank you so much! I've seen a lot of conflicting information about HttpClient and using 1 instance of it for the life time of the app just because it implements IDisposable. I completely understand that using one instance of HttpClient in a console, windows forms, wpf, etc is fine, but what about in web mvc projects. Isnt it slightly different because if you have a static var holding the instance of HttpClient isnt that shared across everyone using your web app/site, also what is the best way to hold that once instance var for mvc? I should point out that the reason why I found your video is because I have a web app that Im building that uses a few different apis, and Im wondering how to use HttpClient instances that are kept for the lifetime of the app when Im using mvc5 and if that really is the best practice for each of the external api's Im using as each one would need a separate HttpClient as the base url address would be different
So they've made the HttpClient a lot better in .NET Core. Check out this video on it: th-cam.com/video/cwgck1k0YKU/w-d-xo.html Basically, you use the HttpClientFactory to create clients for you (or recycle them - it doesn't matter to you which it chooses to use). That way they are safely created and disposed without overloading the system or exhausting the ports.
Two small questions. What did you do in 49.56 to make SunProcessor visible here? using DemoLibrary is not in my option list, so I added it by myself in the using section while making it public. And second, what is sunriseText? Where did you define it?
I used the suggestions menu (Ctrl+.) to add the suggestion of referencing the class library and adding the using statement I needed. It is a shortcut to doing it manually. The sunriseText is a textblock on my form.
Thanks Tim for amazing videos only thing I would mention is that if you could please zoom visual studio so that it fits my mobile screen that would be amazing.. Most of your videos I watch are on mobile..much appreciated and keep up with the good work . Thank you
Trying to accommodate mobile viewing is tough, since there is so much to show. I've tested out doing something like that and it always ends up distracting.
Great video! I did think though that you were going to look at API calls through a wrapper. Ie, calling a library written in C from C#. Maybe a future subject 😉👍
Hi Tim! Great video, I've been following you for a couple of months, is there any vid related with authentication? I'm creating my own app and i don't know yet what would be the best way to authenticate users.
Tim, can you please do a tutorial that covers this with authentication? at least a couple of major methods? I know you decided not to cover it, but it'll complement this video nicely.
Tim, have a question. What exacty means integrating API means? I saw a job description where they mentioned they need Dot Net Developer with API Integration experience? Is it same as calling external APIs in our application?
one question, been watching your SOLID videos and am wondering if the "newing up" of HttpClient and some other stuff in the ApiHelper class is considered as acceptable for some reason, or if you just did it to keep things simple for the video. Would you recommend using something like DIP here? or would it be overkill for this type of application, trying to get a bit of a sense of when and where to use the principles as I'm aware over use of them is a common thing, especially for those who have just recently understood how to use them and why. Thanks again for your videos btw 10/10 :)
Good questions. The HttpClient has always been a sticky issue since it was something that, if done wrong, could cause socket exhaustion. There have been some major improvements in .NET Core and now we can ask for a HttpClientFactory (from DI) and then use the clients as needed without worrying about socket exhaustion (the factory takes care of when to create new ones, etc.)
I dont get the ReadAsAsync when setting up the comic processor. I get either ReadAsByteArrayAsync, ReadAsStringAsync or ReadAsSteamAsync. What did i do wrong?
I second this hard, I've been jumping back and forth between which gql client library to use or whether to use a client library at all instead of the bare httpclient class.
Hi, thank you, your videos are very helpful. I have a question, how should I name my properties in the case when filed in JSON called "solar_noon" or "civil_twilight_end"? Should I name them like Solar_noon or Civil_twilight_end. Is there some solution that let you name properties in CamelCase?
I typically just match the names. That is simplest. However, you can use attributes to identify what the JSON name is and then use a more C#-like property name.
Hey, big fan! Do you have any videos on how to post to an API server? I'm able to get, but no matter what I do, I'm getting a 400 when I try to post. Not sure what's happening, and I've spent hours and hours debugging. Would love to see how you actually do it. Thanks!
I have a noob question. I thought an API runs completely separate from a programm and it gets http requests or posts. In this example the WPFApp is using Demolibrary and then calls the methods. This makes me thing that in a real scenario, if many clients run an application then they have to be compilated with the API included??? or there is only one API running in a server that gets http requests and answers to everyone? this concept is not clear for me...
The API itself is a single instance that runs on the server.* Each client would then connect to that server and call the API to send/receive data to/from the server.
Hey Tim, nice channel :) . I have a question. I am a bit confused about lifecycle of HttpClient. I have checked many resources according to this topic, but they all seems to have different opinion on the topic. Should I create a new instance of HttpClient inside an using block every time while making specific request or should I make HttpClient instance to be reused in whole application aka make it singleton ?
It is the recommendation from Microsoft to open the connection once and use it throughout the lifespan of your application: docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client#create-and-initialize-httpclient
Hi Tim, i tried to do as your video but with web form and got this error: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked . This exception may also indicate an attempt to call an "async void" method, which is generally unsupported within ASP.NET request processing. Instead, the asynchronous method should return a Task, and the caller should await it. I already marked the Page with Async = true. Below is my code: protected async void btnTest_Click(object sender, EventArgs e) { var a = await UserProcess.LoadUserInformation(); FirstName.Text = a.Value; } Could you please help to advise how to fix this error? Thank you so much.
Thank you so much. This was a very helpful video for me as I'm building out a new app that heavily utilizes JSON data. I recreated your lesson here using Xamarin and it all works quite well. However, my next big challenge is to consume JSON data which is stock price data and so my JSON has many rows that contain "high" "low" "open" "close" data. In your "Processor" class, could you demonstrate the code you would use to cycle through and deserialize that JSON into a Collection/List that can then still be accessed on the front end? There are a lot of example floating around out there, but I can't find "the one" that actually works. Any advice is appreciated.
Not sure what you are looking to have demonstrated. If you have an array of objects coming back, just as for it as a List during deserialization and it will work.
Hello Tim I am still having issues with the WPF stuff. I miss the old winforms. I just want to import the data in a list in stead of different variables. Can u please help?? I made a class where i create a list consisting of the modelclass (variables) but what do i do from there?
Still churning out new videos and immediately responding to comments from 3-year old videos :-) You're a credit to the community! Thanks for the videos and keep up the good work.
You are welcome.
I have watched a few videos about calling API's. And I originally skipped this one because of the length, and I was so anxious to get started. After taking the time to watch it, I regret skipping over it. This video was so informative, and Tim really has a way of explaining everything very thoroughly. I am now a fan, and will be watching as many of your videos as possible. Thank you for taking the time to create these videos.
Thanks for watching and trusting Tim to help expand your skills
0:00 - Intro
1:00 - Demo application walk-through
4:09 - Setting up API calling: WebApi.Client and Newtonsoft.json NuGet references
6:02 - Setting up API calling: HttpClient
13:48 - Setting up API calling: API calls
19:14 - Setting up API calling: Reading and working with json data
28:18 - Loading image in WPF (form a website)
35:29 - Adding events in WPF application: wiring up action buttons
39:40 - Note on information Cashing
42:55 - Sunrise-sunset API: Nested json objects, API calls, WPF events, displaying information
51:56 - Loading other WPF forms from MainWindow
53:38 - Summary and concluding remarks
Thanks again. You are helping the entire community with these. Much appreciated
J
I just started my first ever api project at work. This video really saved me. Very clear. Tremendously helpful.
Great!
As a newbie to coding in general i appreciate the advice on the comic model. Just specifying the properties you need is golden nuggets. I’m always like ‘give me all the things magical internet box’ and I’ll figure out what I need, whilst my program grinds to a halt. Thank you Tim Corey for knowing what I need before I do.
I am glad it was so helpful.
I've been confused about API and integrating with C#, watched various videos about this subject and was still lost, your explanation has made it more clear. Thanks for your tutorials - looking forward to the continued courses.
I am so glad I was able to clear up the confusion for you.
Luckily I found this video. You're the only one who can describe these techniques in an organized way. I just subscribed to your channel too.
Thanks and welcome aboard.
I wondered how to connect to a web API for a long time. I sought out for the resolution for a long time and I couldn't understand anything until I've watched this video. Thank you a lot, sir.
Glad I could help!
I wish I could "like" this video more than once. You are a great teacher.
Thank you!
@@IAmTimCorey Do you have and videos on WINUI?
I am probably a crappy starting up programmer who rarely subscribes to channels and rarely ever likes videos. For you I make an exception, this video was super helpful and this kind of content is rarely ever free. Thank you and God Bless the beard.
You are most welcome.
Great video, one of the best on TH-cam when it comes to C#
Thanks!
Thank you, Tim for pouring down all the information ( as much as you could ) from your heart and not holding anything back!!!!
I'm feeling lucky to got stumbled upon this video amongst plethora of content out there!!!! Looking forward to learn new things about programming/coding/web development!! THANK YOU SIR!
You are most welcome. Thanks for watching.
Thank you! I really appreciate how you have given back to the c# community.
You are welcome.
I just got an assignment for a job where I had to do exactly this and it helped me alot. Thank you!
Awesome!
Did this in generics because of knowledge from your other video about generics. Thank you, always happy to take a challenge when you suggest something extra.
Excellent!
That's an amazing and hard to find sort of tutorial on youtube, thank you!
You are welcome.
Tim, Great tutorial. I would recommend anyone watching this to watch it all the way through. This really simplified everything I seen online. Too many people were making this really complicated but you solved that. I was originally looking for a tutorial on just getting and using data from a REST Api, after that was going to review getting images from that Api and displaying them in the app and then cycling from page to page. Tim I would recommend a different title on this video though which is why I went down the rabbit trail looking at other videos first. "C# WPF XAML REST API Tutorial - Examples, Best Practices, Memory Management, and Pitfalls" Though I have been programming for 20 years I am new to C# and I know ASP.NET uses C# and there is a difference between WPF XAML and Forms - hence my I suggest adding in those other 2 to the title. I subscribed and look forward to lots more videos.
I am glad you enjoyed the video.
I don’t really comment often but I just want to say thank you so much. You have been a really big help on a side project I’m working on and you explained everything so well!
I'm so glad!
Thanks Tim, these concepts helped me in an interview
Awesome!
Great Video Tim, I always wait for your new videos, can you make a video on Serialization and Deserialization, Thanks
I'll upgrade the priority of that on my suggestion list.
Thanks for the video.
The sunrise-sunset security certificate expired 7 days ago. I have dropped the s from htpps and everything works.
Thanks for sharing.
Since i got stuck with this problem, it might be helpful to other beginners : if you are using an API that requests a simple token identification, pass the token as a header, not in the uri, as such:
APIClient.DefaultRequestHeaders.Add("Authorization", "YourTokenHere");
Correct. We actually just covered this today in the TimCo Retail Manager course video.
@@IAmTimCorey yop, just watched it! a few hours too late for me :D
whats with refresh token?
Thank you Sir. Can you please do a video on serialization and deserialization in C# may be considering a wpf datagrid serialized into XML. I found
many examples, but when you explain it will be complete for sure
It is on the suggestion list.
At 23:47 ReadAsAsync cannot be found, in fact, I can't find any extension methods. When I type in ReadAsAsync it says 'HttpContent' does not contain a defnition for ReadAsAsync. I've downloaded your code, and I can't find what I did wrong . EDIT: the mircosoft web api nuget package was not installed for some reason
Glad you got it figured out.
Thank you for this video, it cleared a lot of confusing stuff about using API's up for me.
Keep up the good work!!
Greetings from Austria
Great!
Hey tim, are you planning on doing a video about hosting a mock of an api with predetermined responses?
If not, do you have any video / guide you might recommend?
It isn't on the schedule but I can add it to the suggestion list. I don't have any current recommendations on that topic.
Hi tim, another question: what do you think of the term "Full Stack Developer"? Do you consider yourself more "back-end" oriented, "front-end" oriented, or both?
I'm definitely a full stack developer. I can (and do) create user interfaces and I can/do create data access as well as everything in between. As far as what I feel about the term, I think it is fairly descriptive. Sure, usually people can do both but it is very common to specialize in one side or the other. The larger your company/team is, the more likely it is that you will specialize in one area. You get really good in that area and you may even let your other skills fade a bit (or you just don't keep up with the newest changes).
Firstly, i would like to say thank you for everything you are doing on here. you are a legend.
Secondly, can you explain why you have chosen xaml over windows form, could the same outcome be achieved in both?
The same can be achieved with WinForms, yes. WPF is a more modern UI platform, which is why I default to it.
The ReadAsAsync() function is no longer available what is the fix for this?
I had the same problem. You need to reference the ...WebApi.Client NuGet
One more thing: I had to add this line:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
to the InitializeClient() of the ApiClient. If not I was getting a HttpRequestException: "The request was aborted: Could not create SSL/TLS secure channel."
The exception occurred in ComicProcessor.LoadComic(), probably because my environment is a bit different, VS2015, .NET Framwork 4.5.2
I got the same Error and was able to fix it with your fix. Thank you.
I'm glad you got it to work. Thanks for sharing.
Hi, I am writing an application that will continuously run on a server to make a call to an API every hour. At what point should I enter the API key. Should this be done inside the InitializeClient void or will cause security issues having this open continuously?
Huge thanks man, was a bit disappointed you didn't explained how to caching and authenticate using OAuth2
Trying to cover authentication is tough because everyone does it differently. Usually the API documents how to do that. As for caching, I'll be covering that in a future video.
Tim, I need to tankyou, your classes are great, you have one of the bests teaching aproach I've ever seen. Keep this way, you are helping a lot of people. Tanks again, god bless!!
I am glad you are enjoying the videos.
Hi, could not find an answer on the internet, so maybe you will help me. I heard that there is a new way of calling an API without NuGet packages. It already works without Newtonsoft but ReadAsAsync only exists in the NuGet package. If you know the answer, can you point me in the right direction?
Okay done. If somebody has the same question, I did it using System.Text.Json and this helped me: www.pmichaels.net/2020/02/22/my-object-wont-deserialise-using-system-text-json/
Would you happen to have a tutorial like this, but from the beginning, such as creating the boxes with "previous" "sun information" "next" etc?
This playlist should help: th-cam.com/play/PLLWMQd6PeGY3QEHCmCWaUKNhmFFdIDxE8.html
ohhh thank you soo much! i made a weather program with a console app. it did run succsessfully, but i didn't understand how the properties worked. this video helped me understand it! :)
I am glad it was helpful.
Hi Tim - what made you want to use a static method for the instantiation of the ApiHelper.ApiClient instead of via constructor? What I typically do is create a customized httpClient in a class that inherits from HttpClient. This way I can use DI to bring it in. Any thoughts on this?
can u make video how to parallel use api or post/get requests
imagine i need to registrate accounts but nor one by one
how to registrate accounts for example in 10 tasks each of them have different proxy, coockie and exc.
or can you give link with any example of it
ty for ur staff
I'll put that on the list for a follow-up video. In the meantime, you could probably do a parallel.foreach like I demonstrated in my Advanced Async video.
thank you very much Tim you are helping people a lot
with your amazingly explained tutorials!
Glad you think so!
Great tutorial as usual from you Tim, gj! Keep it coming..
Thank you!
Hi Tim! In your video you mention building a generic Api data processor. Have you made or are you planning on making a course on that subject? ...and thank you for your videos!!
Hi Tim, does the values of LoadSunInformation update for each day? In addition does this tutorial include constantly updating information when the JSON or website file is update?
Hi Tim, could you please briefly explain to me what's the difference between making the ApiHelper class static and then calling the InitializeClient() method vs. making a non-static class and registering it as Singleton service in the Startup.cs (as services.AddSingleton() ...) Thanks!
In this case, it was because we weren't using dependency injection (this is a .NET Framework project so it doesn't have DI built-in like ASP.NET Core projects do). If I had DI available and this were a "real" app, I would implement the class as a singleton, since it allows for constructors, interfaces, and more.
@@IAmTimCorey Thanks for the explaination! Love your work
Omg just what i needed. Love you
Excellent!
Hi Tim, I followed this tutorial but the return type of the api is inside an array like this [{"kenteken":"83MHKP","brandstof_volgnummer":"1","brandstof_omschrijving":"Benzine","geluidsniveau_rijdend":"74","geluidsniveau_stationair":"93","milieuklasse_eg_goedkeuring_licht":"(EU) 134/2014","nettomaximumvermogen":"84.60","toerental_geluidsniveau":"5000"}]. Now I get an error when I run this code: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in System.Private.CoreLib.dll. Do you know how I could solve this error?
My guess is that your model you are trying to map to is not correct. Are you telling Newtonsoft that it is a List or just T? You need to say it is a List since it is an array.
Thanks for this wonderful video, i had to use 1.25 speed :D . I added a buffer to store existing calls results ,a spinner to show Ajax call in progress and a button to read out ALT text :D BTW, this Comics are kinda fun to read
You are welcome.
Thank you Tim once again for great content ! Super helpful, now I just need to practice making calls to other APIs so that it sticks. :)
You are welcome.
Hi Tim. Is there a pattern available to handle APIs that work based off a Request/Response with Events? To be more clear: The API accepts a Request Type and a Request ID, and raises an event when the request is fulfilled, referencing the Request ID. My first take on this involved a lot of globals to manage state and flow and all sorts of code in the event handlers, and having not looked at it months, I'm lost as to where I was going with it.
We love you tim Corey
Thank you.
Excellent tutorial, now understood how it works, but was wondering if you requesting any files or PDF through API? what sort of properties would we use to display files instead of text?
I don't have any videos on that yet but in general, you need to use a file stream and a file picker on the UI.
@@IAmTimCorey yeah I used stream and memory stream with byte array and retrieved the document. 👍👍👍
Hi Tim, is it possible to apply/use the ApiHelper class on a ASP.NET MVC app? If so, how do I use the InitializeClient method?
Yep. You would have less to do. You would do the HttpClient initialization in dependency injection and pass that into the ApiHelper class. We do that in the TimCo Retail Manager series.
How can I call the API we made in your Intro to WebAPI? Just use the localhost url instead of the xkcd?
Pretty much. If you have authentication on your API, you will need to do more. The TimCo Retail Manager series ( th-cam.com/play/PLLWMQd6PeGY0bEMxObA6dtYXuJOGfxSPx.html ) creates an API with authentication and connects to it using WPF. That would be a good example to follow.
Great video. how do you actually do caching??? you mentioned it was very easy to set up.
save the picture on disk then retain the uri to that file when asking for an already loaded picture (with a dictionnary probably?).
Pretty much. I usually save the data to a small database (SQLite, MongoDB, etc.) and the images to disk in a temp folder. I also save the API call parameters or the entire call to the database too. When a call comes in for the exact same data, I go to my database instead. You just need to know how long to cache it for based upon the resource. For example, sunrise/sunset data doesn't change for the same exact data. I could keep that forever. Stock market data changes a LOT so I might only cache the data for 15 minutes (if it was an informational application) or not at all (if it was an investing application).
So how do you know that you receive the exact same request? Will you check every request in DB first if it exists?
9:25 Is there a reason you cleared the default accept headers before adding any? I don't think creating a new clients puts any defaults in there
A good practice. Just because something should be true doesn't mean it is.
Hi Tim,
have you got a tut where is shown how to get data from API when having Authorization with tokens?
Check out the TimCo Retail Manager series. Right now we are wiring a Blazor WebAssembly application to an API that has authentication with bearer tokens which include role authorizations. We also wired up a WPF project to the same API.
Thanks Tim,have a nice day!
You are welcome.
Good video.
I don't know why they have to make these packages so complicated. I'm trying to build a simple API client that sends a JSON payload with custom HTTP headers used for authentication and expects a JSON response on success or failure. It doesn't need to be asynchronous because I don't want the application doing anything else while the call is out or until the call times out. The JSON is being handled with Newtonsoft's Json.net. It just seems very difficult to find human readable documentation about system.net.http that shows how to do such a thing.
I think part of it is that you are expecting to do something that isn't simple. That list of requirements entails quite a few things. Dropping async isn't really possible/necessary since the web is, by default, asynchronous. This video shows you how to connect easily to an API and get the data you need.
@@IAmTimCorey Interestingly enough, after posting this comment I decided to try and decipher Microsoft's official docs on HttpClient and was able to get the skeleton functions up and running. It actually wasn't that difficult once I used my secret decoder ring to translate MS speak to plain English. Plus, I planned out exactly what my app was going to do before I wrote a single line of code, as you mentioned in one of your videos, so I knew which functions fit my requirements after a little bit of reading.
BTW, I know your courses were made a while back but your videos have been instrumental in helping me get this app up and running. I'm a photographer, not a software developer so this has been one HUGE learning experience in the month since I started learning C#. Thanks for putting all these videos out there. I'm definitely considering purchasing your course, to say thank you.
Agreed, .NET's existing libraries are verbose and the documentation is hard to digest.
From my personal l can highly recommend any of these free, open-source NuGet packages. These are all well maintained & make for a much better developer experience:
1. ServiceStack.Text( 1k GitHub stars, 7m Nuget downloads) - fast light and resilient.
2. RestSharp (6k GitHub stars, 23m Nuget Downloads) - Simple REST and HTTP API Client
3. Flurl (1.7k GitHub stars, 3m Nuget Downloads) - a fluent, portable, testable HTTP client library
You're a pro-hacker at 2x speed Tim.
lol
Great video. One question: What if a json response from an api contains an array? How do you map that to properties?
For example:
"weather": [
{
"id": 804,
"main": "Clouds",
"description": "overcast clouds",
"icon": "04n"
}
]
In this specific example, you could have this property: public List Weather { get; set; }
You can also paste the json into C# using the Paste Special option to see how the class structure would work.
Hi Tim. Thanks for all the great content. This may be one for the back burner or a separate resources video related to consuming rest APIs. There seem to be a wide variety of tutorial videos that relate to consuming a single endpoint, but not really anything that I've been able to find in terms of completing an "object graph". For example, if there's a theroetical API with a single product endpoint that can be retrieved via simple id key and that product has a number of related lookup id's for other related objects with separate endpoints - what would the options be in retrieving those or keeping them either cached or in memory to improve the efficiency of requests? Many thanks
Thanks, I had added it to my list
Hi,
When running the program at 33:46. Am getting the error “Program does not contain a static “Main” method suitable for an entry point” - what a wrong with my code?
Thank you for the help’
It sounds like you are trying to start your class library instead of your API project. Right-click on your API project and select "Set as startup project".
Hello Tim,
I have the following question:
In this video you have the controller that actually does the job.
I saw however that on your TimCo retail series you have a controller that defines what should get post etc actually do..
I tried to extend your video here to get data from another api without success. The notions are not so clear yet (and I haven't finished your timCo retail series videos on API).
So in its documentation (the pi i want to use) says for example: the end point url is blabla ( no free advertising :P). If you want to get a random fact from the endpoint go for GET /facts/random. I build exactly the request as you did here, and I expected that a url blabla/facts/random would do the trick. It does nothing though ( SunInfo = null). What am I missing? Were am I mistaken?
Try calling the API in Postman. Make sure it returns a value that you expect. Then make sure your model you are capturing it into is laid out correctly.
Love your classes, best wishes from Argentina AR
Awesome! Thank you!
Been waiting for this, Like forever.
Well, I'm glad it finally came for you.
This video covered exactly what I've been trying to figure out. Every thing I got from SO was basically the same code snippet a million times and wasn't helpful.
I'm glad the video was so helpful.
Thank you!
I was just making similar things in my project, trying to figure out the best practices. GET is cool, but I also need to POST things and I guess I have found them with title: Posting Sales Data to an API - A TimCo Retail Manager Video.
Also looking forward watching all the Role management videos, cause I also implemented the default web api authorization using /Token. So far I was just doing manual service calls with Postman, to make users, roles, and adding roles to users :D
I'm glad you are finding the resources you need to accomplish your mission.
Hi, I currently trying to code the first part, with the display of a comic on the windows, but I get this exception : "httprequestexception was unhandled by user code", with the additional information : "An error occurred while sending the request". This exception is linked to the line "await LoadImage();" in the main windows, or it is linked to the line "using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))" of the comicProcessor. I tried also to test your code but I get the same exception. I use Visual Studio 2015, can it be the problem?
That's my guess. It worked for me and if you are running my code, my guess is that the difference is the version of Visual Studio.
ok, so the thing here is that the wording of VS 2015 is missing an important point and I was not able to solve this, so I installed VS 2019, same error, however, there was additional error message, and I managed to find a solution, you have to add this under the "private async Task LoadImage(int imageNumber = 0)"
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
If this doesn't work, try this:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
For more info: stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel
Do you also have a video on how to make proper post calls using this same style? I would like to know what the proper way of posting data to a service that would send it to a database. You don't exactly want sensitive data being visible on the web. It would also be nice to look at this in the way of registering a user and logging in since it's a real life and practical example.
I do not yet but it is coming. The key is that I have to pick one API for uploading. In this case, I will make my own but what I do in that won't be the same as what you do with other APIs. As for sensitive data, if you POST data and you are using HTTPS, you are protected (or at least 99.9% protected).
Thank you Tim. This was very informative and helped a lot.
You are welcome.
hi Tim, you mentioned authentication, why not cover basic authentication, token-based, and the one that uses grant type = client_credentials (oauth 2.0), that would be awesome! thanks
I will add it to the list. Thanks for the suggestion.
Please!
@@IAmTimCorey ya man please do , i want to use for trello lets say
api.trello.com/1/boards/?key=0123token=123name={name}'
like i put my key i put my token then in the name what do i put when i put the name lets say like this -> its not working
This is to create a board:
api.trello.com/1/boards/?key=0123token=123name=yolo
Then it says :
Cannot GET /1/boards/?key
developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-post
Do i need to do something else before trying to put the name et.c
You can add this to your code if you're stuck. I'm not sure if this is the correct way but it works.
replace bas64tokenhere with your base64 encoded username:password
// ApiHelper.cs
ApiClient.DefaultRequestHeaders.Accept.Clear();
ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ApiClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", "base64tokenhere");
Yet another one of your videos that addresses something I am working on, your channel is great man thank you so much!
I've seen a lot of conflicting information about HttpClient and using 1 instance of it for the life time of the app just because it implements IDisposable. I completely understand that using one instance of HttpClient in a console, windows forms, wpf, etc is fine, but what about in web mvc projects. Isnt it slightly different because if you have a static var holding the instance of HttpClient isnt that shared across everyone using your web app/site, also what is the best way to hold that once instance var for mvc?
I should point out that the reason why I found your video is because I have a web app that Im building that uses a few different apis, and Im wondering how to use HttpClient instances that are kept for the lifetime of the app when Im using mvc5 and if that really is the best practice for each of the external api's Im using as each one would need a separate HttpClient as the base url address would be different
So they've made the HttpClient a lot better in .NET Core. Check out this video on it: th-cam.com/video/cwgck1k0YKU/w-d-xo.html
Basically, you use the HttpClientFactory to create clients for you (or recycle them - it doesn't matter to you which it chooses to use). That way they are safely created and disposed without overloading the system or exhausting the ports.
Two small questions. What did you do in 49.56 to make SunProcessor visible here? using DemoLibrary is not in my option list, so I added it by myself in the using section while making it public.
And second, what is sunriseText? Where did you define it?
I used the suggestions menu (Ctrl+.) to add the suggestion of referencing the class library and adding the using statement I needed. It is a shortcut to doing it manually. The sunriseText is a textblock on my form.
This is another great tutorial. May I ask if you can do a tutorial about POST method on API in C# Best Practices, Memory Management and Pitfalls
Great suggestion! ... added to the list.
Thanks Tim for amazing videos only thing I would mention is that if you could please zoom visual studio so that it fits my mobile screen that would be amazing.. Most of your videos I watch are on mobile..much appreciated and keep up with the good work . Thank you
Trying to accommodate mobile viewing is tough, since there is so much to show. I've tested out doing something like that and it always ends up distracting.
Hi Tim. Great video, really helpful for someone coming from JS and React. Do you have a video on how to access nested objects in a JSON response?
Not specifically, although when you parse the JSON into an object, it can handle nested objects.
What is the project type of DemoLibrary above WPFApp? I haven't really worked with multiple projects in single solution before.
It is a Class Library. They are really important to know so definitely check them out.
Do you have a tutorial with sending post request with authentication to an API?
Check out the TimCo Retail Manager series. In it, we build and use an API with authentication. We call it from WPF.
Did you make a video covering posting data to an API? Thank you.
Check out the TimCo Retail Manager. We do that and more in that series.
Great video! I did think though that you were going to look at API calls through a wrapper. Ie, calling a library written in C from C#. Maybe a future subject 😉👍
Ah, I see. I'll add that to the suggestion list.
Hi Tim! Great video, I've been following you for a couple of months, is there any vid related with authentication? I'm creating my own app and i don't know yet what would be the best way to authenticate users.
Take your pick - th-cam.com/users/IAmTimCoreysearch?query=auth
@@IAmTimCorey awesome, thanks bro. Keep it up
Tim, can you please do a tutorial that covers this with authentication? at least a couple of major methods? I know you decided not to cover it, but it'll complement this video nicely.
Well, the TimCo Retail Manager series creates a WebAPI that it then calls from WPF with authentication and authorization. That is one example.
Thanks Tim. Wanted to check if you have any series for automating apis
Automating them? No, sorry.
Tim, have a question. What exacty means integrating API means?
I saw a job description where they mentioned they need Dot Net Developer with API Integration experience?
Is it same as calling external APIs in our application?
That is what it sounds like.
one question, been watching your SOLID videos and am wondering if the "newing up" of HttpClient and some other stuff in the ApiHelper class is considered as acceptable for some reason, or if you just did it to keep things simple for the video. Would you recommend using something like DIP here? or would it be overkill for this type of application, trying to get a bit of a sense of when and where to use the principles as I'm aware over use of them is a common thing, especially for those who have just recently understood how to use them and why. Thanks again for your videos btw 10/10 :)
Good questions. The HttpClient has always been a sticky issue since it was something that, if done wrong, could cause socket exhaustion. There have been some major improvements in .NET Core and now we can ask for a HttpClientFactory (from DI) and then use the clients as needed without worrying about socket exhaustion (the factory takes care of when to create new ones, etc.)
I dont get the ReadAsAsync when setting up the comic processor. I get either ReadAsByteArrayAsync, ReadAsStringAsync or ReadAsSteamAsync. What did i do wrong?
Appears to be missing from 5.2.7
Check your using statements. You might be missing one.
you seem to be missing the following class "HttpContentExtensions"
As always, a fantastic tutorial. Learned a lot. Thank you. Could you do a similar tutorial on how to query GraphQL with C#?
I will add it to the list. Thanks for the suggestion.
I second this hard, I've been jumping back and forth between which gql client library to use or whether to use a client library at all instead of the bare httpclient class.
Thank you so MUCH! This was awesome!
You are welcome.
Hi, thank you, your videos are very helpful. I have a question, how should I name my properties
in the case when filed in JSON called "solar_noon" or "civil_twilight_end"? Should I name them like Solar_noon or Civil_twilight_end.
Is there some solution that let you name properties in CamelCase?
I typically just match the names. That is simplest. However, you can use attributes to identify what the JSON name is and then use a more C#-like property name.
As always, excellent video!
Thanks!
Hi Tim, I could really use some help implementing a double nested array, any help is very appreciated
This is great thank you, but how do I do this when the api returns xml? Also how do I handle json when it is returned in an array?
C# should be able to parse XML like JSON (although I haven't done it in a while). As for an array, just capture it in a List.
Is advanced video for this one came out? like youve said in the end
Hey, big fan! Do you have any videos on how to post to an API server? I'm able to get, but no matter what I do, I'm getting a 400 when I try to post. Not sure what's happening, and I've spent hours and hours debugging. Would love to see how you actually do it. Thanks!
I've got one on the short list for upcoming videos that will work with how to call a WebAPI from a client (including posting data).
I have a noob question. I thought an API runs completely separate from a programm and it gets http requests or posts. In this example the WPFApp is using Demolibrary and then calls the methods. This makes me thing that in a real scenario, if many clients run an application then they have to be compilated with the API included??? or there is only one API running in a server that gets http requests and answers to everyone? this concept is not clear for me...
The API itself is a single instance that runs on the server.*
Each client would then connect to that server and call the API to send/receive data to/from the server.
He is demonstrating an API client in his program which consumes the API that is hosted on the comic website.
what if im calling api in mvc app , should i need to make httpclient static in that case too ? thanks
It depends. Probably unless you are in the same location. Then you can call the methods directly (usually).
Hello Tim! How about calling APIs from c# with OAuth 2.0 implicit flow?
I will add it to the list. Thanks for the suggestion.
Hey Tim, nice channel :) . I have a question. I am a bit confused about lifecycle of HttpClient. I have checked many resources according to this topic, but they all seems to have different opinion on the topic.
Should I create a new instance of HttpClient inside an using block every time while making specific request or should I make HttpClient instance to be reused in whole application aka make it singleton ?
It is the recommendation from Microsoft to open the connection once and use it throughout the lifespan of your application: docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client#create-and-initialize-httpclient
Hi Tim, i tried to do as your video but with web form and got this error:
An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked . This exception may also indicate an attempt to call an "async void" method, which is generally unsupported within ASP.NET request processing. Instead, the asynchronous method should return a Task, and the caller should await it.
I already marked the Page with Async = true. Below is my code:
protected async void btnTest_Click(object sender, EventArgs e)
{
var a = await UserProcess.LoadUserInformation();
FirstName.Text = a.Value;
}
Could you please help to advise how to fix this error? Thank you so much.
I'm not sure how to resolve this issue. I'm not sure how async interacts with WebForms.
Thank you so much. This was a very helpful video for me as I'm building out a new app that heavily utilizes JSON data. I recreated your lesson here using Xamarin and it all works quite well. However, my next big challenge is to consume JSON data which is stock price data and so my JSON has many rows that contain "high" "low" "open" "close" data. In your "Processor" class, could you demonstrate the code you would use to cycle through and deserialize that JSON into a Collection/List that can then still be accessed on the front end? There are a lot of example floating around out there, but I can't find "the one" that actually works. Any advice is appreciated.
Not sure what you are looking to have demonstrated. If you have an array of objects coming back, just as for it as a List during deserialization and it will work.
Hello Tim
I am still having issues with the WPF stuff. I miss the old winforms. I just want to import the data in a list in stead of different variables. Can u please help?? I made a class where i create a list consisting of the modelclass (variables) but what do i do from there?
I have a complete playlist on WPF that should help: th-cam.com/play/PLLWMQd6PeGY3QEHCmCWaUKNhmFFdIDxE8.html