← 返回 doordash 的题目列表Code Craft: Aggregate Data from Multiple Mock APIs with Retries and Tests
类型:online_judge
Code Craft: Aggregate Data from Multiple Mock APIs (Failures/Retries) and Write Tests
Implement a data aggregation function/service that calls multiple mock APIs, aggregates their responses, and returns a single nested result object.
Requirements
Aggregate across multiple APIs:
Call at least 2+ APIs (e.g., fetch FoodItem metadata, related posts, ratings/likes).
Merge responses into one nested result object.
Failure handling:
When any API call fails, implement a clear strategy:
fail-fast with an error, or
return a partial response with error markers, or
retry and then decide.
Retry mechanism (optional but recommended):
Retry failed API calls up to k times.
Avoid infinite retries; distinguish “fails once then succeeds” vs “fails repeatedly then fails”.
Testing:
Write unit/integration tests covering:
all APIs succeed;
one API fails once then succeeds after retry;
one API fails multiple times and ultimately fails (or returns a degraded result).
Tests must strictly validate the nested result object (deep/field-by-field comparison).
I/O
Input: a resource id (e.g., food_item_id).
Output: an aggregated nested object (e.g., JSON/dict).
Language/framework is not constrained. Focus on engineering: error handling, testability, and clean boundaries.