0

If I have a web application built with MVC 5 and a service using Web API 2. Is it a good practice the following scenario?

MVC UI jQuery --> call Web API 2 endpoint --> which will call another service 

Ex:

  1. Application is at : http://domain.com
  2. When user visits application clicks a button
  3. jQuery click event handler of the button makes a GET REST call to http://domain.com/api/user/getdata
  4. The action GetData from ApiController User makes a GET REST call to http://anotherserver.com/api/something using C# code 5 When the call from Number 4 returns data, the action GetData from Number 4 will return that data to the Number 3 (the original requester jQuery).
2
  • 1
    There is nothing wrong with this. What are you worried about in particular? Commented Nov 28, 2014 at 17:01
  • Just wanted to know if the design of the application is a good practice having a chain of REST calls from one service to another ... Commented Nov 28, 2014 at 18:51

1 Answer 1

1

There is nothing wrong in "chaining" calls. Clearly the longer the chain of calls gets the more points of failure there are and the longer it will take to complete all the round trips.

So the question is: Why are you calling the second REST API indirectly? If it's a legitimate business or design reason then carry on. Otherwise make the necessary changes to call the second REST API directly from the client.

One legitimate reason for separate small services is a clean modular design. Another is highly granular security.

As with many things it's a tradeoff and the right decision is unique to your situation.

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

2 Comments

Basically I have an ASP.NET Web API service as the first service, the second (the last service) service is actually a third party application that provides a REST endpoint which I can call to get the data. The point is that my web api is a custom one and that will be used by the application itself to provide the data and so forth. Basically I don't have control over the last REST Service in the chain.
From what you have described I would say you have the correct design. Any changes to the 3rd party service can be hidden from the client by adapting your intermediate API service.

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.