C# – making http request by ajax or c#

.net coreajaxasp.net-mvcchttp-request

In my web application I need to get data from Wikidata, for example to show item's details. I thought about using ajax for this, but was't sure from where I should to call it, so I asked this question.

But after some thinking, why should I use ajax? I can make http request from my server side code (C#). I can put it into controller, get information from Wikidata, fill out ViewModel and then call View(ViewModel).

What can be some downsides of this? Will it affect performance?

So, question is: ajax or C#?

UPDATE: Before development starting I was thinking if I should develop client part (HTML, JavaScript) and Web API separately. In this case I would use Ajax of course. But I decided at this stage I'll do one MVC application. Because it has server side code anyway (even in View), so I think that http request from C# looks more naturally than JavaScript request.

Best Answer

Usually the overriding reason for making a 3rd party API call server side is that it requires you to have an account, username and password with the 3rd party.

If you make the call client side then you expose this information to the user of your website/app

There are other reasons to consider, perhaps you merge the api data with some other data you only have serverside, perhaps you have more than one provider for the same data and want to switch between them but still provide the same datamodel to your client etc. perhaps javascript just isn't good enough to run your business logic

But, these are more meta-programming concerns about ease of maintainability etc. given the cost of a server side call and the extra step in the network traffic, if you can push it to the client it is usually a good thing to do.