Fetch APIs in parallel and return the highest-priority success
You are provided with an array of API URLs, where the position of each URL in the array indicates the priority of its respective API. The task involves fetching these APIs concurrently and obtaining the result from the highest-priority API that returns a successful response. Should all the API calls result in failure, it’s essential to manage the rejection appropriately. To fetch APIs in parallel, look at Promise.allSettled() and related Promise helpers.
Consider the following example of API URLs:
https://api.example.com/api1https://api.example.com/api2https://api.example.com/api3The objective is to execute these API requests in parallel and secure the result from the API with the highest priority (earliest in the array) that successfully responds. In scenarios where every API call is unsuccessful, the system must adeptly handle the collective failure.