C
C#3mo ago
JuJo2594

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:
No description
No description
No description
9 Replies
Angius
Angius3mo ago
Well the exception is quite clear, isn't it?
Angius
Angius3mo ago
Constructor wants a thing
No description
Angius
Angius3mo ago
You don't give thing
No description
Angius
Angius3mo ago
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?
JuJo2594
JuJo25943mo ago
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 ??
Angius
Angius3mo ago
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 from
JuJo2594
JuJo25943mo ago
I understand that it's more efficient using 'HttpClientFactory' than 'HttpClient' so I just want to practice with it...
Angius
Angius3mo ago
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 endpoint
JuJo2594
JuJo25943mo ago
Thank you for the recomendations,i'll continue checking the documentation and taking your advices... 🙂