0

I make an API call which return a list of items. I use a foreach loop to iterate the JSON data:

 foreach($decoded_results['items'] as $item) {
      $image_link = $item['thumb'];
      $link_url = $item['url'];
      $subject = $item['title'];
 }

I need some additional information for each item and in order to get that I need to call another endpoint.

In my first response every item in the JSON object has a property with an ID that corresponds to a property with the same ID in the other JSON object, that I get as a response when I call the second endpoint. This ID is needed as a parameter in the query string for the second API call.

What would be the best approach to accomplish this? I've looked into curl_multi a little bit but not sure if this is suitable for the situation.

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
Josefine S
  • 23
  • 7
  • Do you have any say in building that API? If so, you could build an endpoint accepting multiple ids and delivering the desired content for those id's. – Andresch Serj Sep 30 '15 at 09:04

1 Answers1

0

The best solution would be if your second API has an endpoint that accepts a list of IDs and can return all the information you need in one call, otherwise it is known as the N+1 problem in database management, it is also the same here and is not an optimal solution.

Community
  • 1
  • 1
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144