Search code examples
djangoapibackendrestful-url

What is the recommended way to handle multiple api calls from angular to backend server on the same page(=angular component)?


I'm a backend developing using python/django stack to build a backend api server for our team's frontend developer, who uses angular2 to build SPA for our service.

There are times when frontend need to make GET api call to two or more separate resources to backend server.

For example, we have payments page, which needs information both from users and products tables.

Is it better to make two separate calls at endpoints as follows:

/api/users/:user_id
/api/products/:product_id

or it better to make backend django server to do some data processing to mix up the information and return the results containing both user-related info and product-related info at a single endpoint as follows:

/api/payments/:payment_id

Which do you think is more standard de facto?


Solution

  • See its totally upto you how will you going to handle this.

    But according to me, if one call is dependent to another's response than you can mix the response on backend side else its better to call indvidually on the client side, reason is response will be faster in this case because there is no time consumption for calculation etc.