The MS docs say "HttpClient is intended to be instantiated once and re-used throughout the life of an application" - this seems fair enough but not so simple when you are using HttpClient from within a web app. All the examples out there using HttpClient are done with console apps and infact i cant find any examples with a web app consuming an API using HttpClient. So my question is whether HttpClient is actually meant to be used from a web app or should i be using WebRequest or something else? Thanks to anyone who replies!
Addition 24hrs later....its a .net framework app. Sorry i only just catching up with the answers, i have never used this site before and assumed i would get an email when answers posted - sincere thanks for all your comments and looks like i have some reading to do
If you are using dotnet core then use HttpClientFactory if not use a private static field for your HttpClient. These are the recommended best practices. The second option still poses some issues but they are more edge cases and won't end up exhausting your sockets. This article explain s things very nicely https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/