1

I am new to the REST world. I am writing an ASP.NET MVC application. My requirement is to make a few REST calls from the client. I can either choose to make these REST calls from Javascript or I can do that in the C# code in the Controller. Which method is recommended? According to my understanding, the Controller runs on the Web Server and the Javascript runs on the browser. So is there any perf degradation if the REST calls are made from the Web Server.

Can someone suggest me the general practice around this? Are there any security gotchas for the same?

Thanks

2 Answers 2

1

Let us consider the pros and cons of doing this Server side

PROs:

  • You can do other processing on the data using the power of the server
  • You are not subject to cross domain limitations like you would be in ajax
  • Generally you do not have to worry about your server being able to access the resource, whereas on client you are at the mercy of users net restrictions, firewalls etc
  • More control over your http response\request lifecycle

CONS:

  • You will have to consume more bandwidth sending the resulting data down to the client.
  • You may have to do more work to leverage good caching practices
  • Dependant on having certain server side libraries\framework elements

Now although we have a much bigger list of Pros than cons... in the majority of cases you will still want to do this on the client... because the issue of double handling the data is actually a very big one, and will cost you both time and money.

The only reason you should actually do it server side is if you need to do extensive processing on the data, or you cannot circumvent CORS (cross domain) restrictions.

If you are just doing something simple like displaying the information on a webpage, then client side is preferable.

Sign up to request clarification or add additional context in comments.

2 Comments

Roysvork, Can you explain more on the Cross-domain part? How does this affect the user? If my web-server and the server where I host my REST service are in the same domain, would there be a problem when accessing it?
If they are both on the same domain then you will not have a problem. Basically it is a security feature of modern browsers that they will not automatically allow ajax calls to a different domain from the web server... there are ways to make it work however.
0

It strongly depends on your situation. If you simple display this data in your page without any actions, you can get it from javascript. If you want to work with this data, transform it, join it with other data or else, i recommend do this operations on server so get this data on server too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.