Search code examples
javascriptnode.jsvue.jsapi-design

Multiple or single API calls?


I'm currently building an application using NodeJS and VueJs.

I've build an API end point that gives me all the data I need. For example it could give me

  1. Best Football Team
  2. Worst Football Team
  3. Team with most goals
  4. Team with least goals

Is it better to have this as one API call, and pass the relevant data to each Vue component using props, or as 4 different end points and then make the request in the relevant component.

If you could explain why, that would be great!


Solution

  • It depends on the performance of your API. If you are doing operation in sequence to return the data then it would be better to have it as different APIs and call them in parallel from your component. You can also go for parallel processing in your REST API.

    However, if your API is returning static data then just keep single api and call it once to get data for each component.