Trying to get a response from an API
Hey there, I'm learning C# and I trying to get a response from an API in a console App but I'm getting this error:
9 Replies
Well the exception is quite clear, isn't it?
Constructor wants a thing
You don't give thing
Constructor angry
also, that
List<object>
💀
Any reason you're using the HttpClientFactory
, by the by? Instead of just using a plain and simple HttpClient
?Yeah but when I'm trying to create an instace of 'HttpClientFactory' I get antoher error like:
Error CS0246 The type or namespace name 'tHttpClientFactory' could not be found (are you missing a using directive or an assembly reference?)
What would be the problem or bad practice ??
The problem would be that you're discarding any and all type safety. You don't get a list of numbers, or people, or strings
You get a list of "eh, whatever"
and
HttpClientFactory
comes built into ASP.NET, which you don't seem to be using, but it also seems like an ASP tutorial/documentation is where you got the idea to use it fromI understand that it's more efficient using 'HttpClientFactory' than 'HttpClient' so I just want to practice with it...
There's nothing to practice with tbh
httpClientFactory.CreateClient()
gets you a HttpClient
instance
That's all there is to it
As a side note, I don't think a Javascript file would make for a good API endpointThank you for the recomendations,i'll continue checking the documentation and taking your advices... 🙂