Fork this project and share your github link with the implementation please
Build an API endpoint that:
- Receives a video file and campaign ID
- Distributes this video to multiple services in parallel
- Waits for all responses (with appropriate timeout handling)
- Returns a consolidated report of all services' statuses and responses
- Use typescript
- Endpoint:
/api/distribute
- Method: POST
- Request Format:
- Content-Type: multipart/form-data
- Body:
video
: File (required)campaignId
: String (required)
The following services are available for integration:
-
Service 1
- Endpoint:
api.postclips.com/api/code-challenge/service-1
- Processing time: 5 seconds
- Endpoint:
-
Service 2
- Endpoint:
api.postclips.com/api/code-challenge/service-2
- Processing time: 15 seconds
- Endpoint:
-
Service 3
- Endpoint:
api.postclips.com/api/code-challenge/service-3
- Processing time: 45 seconds
- Endpoint:
Each service expects:
- Method: POST
- Content-Type: multipart/form-data
- Body:
video
: File (required)campaignId
: String (required)
{
"success": true,
"message": "Service X completed successfully",
"campaignId": "CAMPAIGN_X",
"videoName": "uploaded-video.mp4",
"service": "service-X"
}
- 400: If video is missing
- 500: For internal server errors
Expected Output from Your Endpoint Your endpoint should return a consolidated report in the following format:
{
"timestamp": "2025-04-24T15:30:45Z",
"overallStatus": "partialSuccess",
"services": [
{
"service": "service-1",
"status": "success",
"responseTime": 5123,
"response": {
"success": true,
"message": "Service 1 completed successfully",
"campaignId": "CAMPAIGN_X",
"videoName": "uploaded-video.mp4",
"service": "service-1"
}
},
{
"service": "service-2",
"status": "success",
"responseTime": 15345,
"response": {
"success": true,
"message": "Service 2 completed successfully",
"campaignId": "CAMPAIGN_X",
"videoName": "uploaded-video.mp4",
"service": "service-2"
}
},
{
"service": "service-3",
"status": "error",
"responseTime": 60000,
"error": "Request timed out after 60 seconds"
}
]
}
- Implement proper timeout handling (suggest 60 seconds per service)
- Process all services concurrently
- Handle partial failures appropriately
- Ensure the endpoint responds even if some services fail
- Include appropriate error handling and logging