Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Crazylife's avatar

How to handle if there's need for multiple API to be called when render a page?

I have a question whereby when there's multiple api to be called, should it be called separately or combined them as one?

For example, i have a page to create product. I have to fetch several data and populated into the dropdown selection.

From the scenario above, should i create another api to return all the required data as a single request instead calling multiple request to get the data?

0 likes
1 reply
tykus's avatar

It depends.

If the external API calls are so slow that your page/site appears unresponsive, I would consider (i) a background job to fetch and cache the third party data so it is available whenever the view is rendering, or (ii) rendering a view which separately makes asynchronous calls for the third party data (with appropriate loading states displayed).

Please or to participate in this conversation.