Server side code or front end code best to call a Protected Web API

Newbie Dev 156 Reputation points
2021-05-08T07:27:37.33+00:00

Hi,

In an Asp.net Core MVC project, is it better to make async call to an Azure AD protected API using frontend technology(jquery/ajax) or should I use the server side code(C#)?

I know if it is frontend code, then it will be faster to load.

But is there any other advantage of using the frontend code?

Is there any code sample to compare?

Thanks

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Yogi 351 Reputation points
    2021-05-10T13:22:40.207+00:00

    If you are calling API with jQuery or JavaScript then the API keys will be threre on the page source. This is very risky so prefer server side calling of API. I am provideing some links to you:

    1. Consuming a Web API in ASP.NET Core MVC with C#
    2. Consuming a Web API in jQuery
    3. Consuming a Web API in JavaScript

    Last but not the least Blazor WebAssemble will be the best as a front end technology for calling web apis - Blazor WebAssembly : Call Web APIs to perform CRUD Operations

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.