This might for some people be a pretty obvious question but i am pretty new to programming and Web Development.
If i need to call an API from an ASP.NET Core MVC application what is the best practice, to do it in C# under the Controller or during it with JavaScript, as i understand both options are available. I am assuming it is best practice do to it in the controller with C# code as the code is (from what i know) not vissible in developer tools as it is with JavaScript.
Are there any reasons to choose the JS code instead of doing it all in C# code?
/Thomas
CodePudding user response:
As far as I know, if you put all codes inside controller to call the web api . it will cause problem. All the page will be refreshed when the client want to post something to backend API.
But if you use js to achieve the same thing, it will not cause this issue. Since by using ajax, it will not make the whole page refresh. It will just post the request to web api and do something after the web api returned the response. This will make your page load speeder and increase the customer experience and reduce the server's load time and reduce server's workload.
CodePudding user response:
Depend on what you are supposed to do.
- If you would call an third parties, other services or other components. You should implement it in your data layer.
- If you just call an your own API (same solution), you should call in javascript code.