This case study demonstrates how Ascoos OS can be used to orchestrate multiple API requests with caching and event-driven logic. The system executes batch GET requests, caches responses, emits success/failure events, and logs activity.
This example uses the following Ascoos OS classes:
- TAPIHandler: Executes API requests with support for caching and events.
- TEventHandler: Emits and logs events for success and failure.
- TCacheHandler: Stores and retrieves cached responses.
- selectCache(): Chooses the appropriate cache type (e.g. file, memcached).
The case study is implemented in a single PHP file:
api_batch_orchestrator.php: Includes batch execution, caching, event handling, and logging.
- Install Ascoos OS. If you’re using ASCOOS Web Extended Studio (AWES) 26, it’s pre-installed. .
- Ensure write permissions for
$AOS_CACHE_PATHand$AOS_LOGS_PATH. - Internet access is required to reach the JSONPlaceholder API.
- Run the script via web server:
https://localhost/aos/examples/case-studies/api/api_batch_orchestrator/api_batch_orchestrator.php
$response = $api->sendGetRequest('posts', ['userId' => 1]);
$cacheHandler->saveCache($cacheKey, $response);
$eventHandler->emit('api.batch.success', ['responses' => $responses]);The script returns a structured array of API responses, logs success or failure events, and stores results in cache. Example output:
{
"posts": [...],
"comments": [...],
"users": [...]
}Want to contribute to this case study? Fork the repository, modify or extend api_batch_orchestrator.php, and submit a pull request. See here for guidelines.
This case study is licensed under the Ascoos General License (AGL). See license.