Bird
0
0

You have nested batch requests where each batch fetches a list of IDs, then fetches details for each ID asynchronously. How should you structure the code?

hard📝 Application Q9 of 15
Rest API - Batch and Bulk Operations
You have nested batch requests where each batch fetches a list of IDs, then fetches details for each ID asynchronously. How should you structure the code?
AUse nested for loops with await inside each loop without Promise.all.
BUse Promise.all for the outer batch, then inside map over IDs with another Promise.all for details.
CCombine all IDs into one request and fetch details in a single call.
DFetch all IDs first synchronously, then fetch details one by one.
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested async batch needs

    Outer batch fetches lists; inner batch fetches details for each list asynchronously.
  2. Step 2: Use Promise.all for both levels

    Promise.all at both levels allows parallel fetching efficiently.
  3. Final Answer:

    Use Promise.all for the outer batch, then inside map over IDs with another Promise.all for details. -> Option B
  4. Quick Check:

    Nested Promise.all handles nested async batches [OK]
Quick Trick: Use nested Promise.all for nested async batches [OK]
Common Mistakes:
MISTAKES
  • Fetching details synchronously slowing performance
  • Trying to combine all IDs in one request without API support
  • Using nested loops without Promise.all causing sequential waits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes