This example demonstrates how to use Taskinity to integrate with external APIs. It shows how to make API requests, process responses, handle errors, and build complete API integration workflows.
git clone https://github.com/taskinity/python.git
cd taskinity/examples/api_integration
cp .env.example .env
# Edit .env with your specific configuration
docker-compose up -d
This will start a mock API server that provides endpoints for testing.
pip install -r requirements.txt
The weather_api.py
file demonstrates integrating with a weather API:
python weather_api.py
The github_api.py
file shows how to integrate with the GitHub API:
python github_api.py
The rest_api.py
file demonstrates a generic REST API integration:
python rest_api.py
The included docker-compose.yml
file sets up:
This example defines the following Taskinity flow:
flow APIIntegrationFlow:
description: "Flow for API integration"
task PrepareRequest:
description: "Prepare API request parameters"
# Code to prepare request parameters
task MakeAPIRequest:
description: "Make request to external API"
# Code to make API request
task ProcessResponse:
description: "Process API response"
# Code to process response data
task HandleErrors:
description: "Handle API errors"
# Code to handle errors
task SaveResults:
description: "Save API results"
# Code to save results
PrepareRequest -> MakeAPIRequest -> ProcessResponse -> SaveResults
MakeAPIRequest -> HandleErrors
HandleErrors -> MakeAPIRequest
This example demonstrates the efficiency of using Taskinity for API integration compared to traditional approaches:
Metric | Taskinity | Traditional Script | Improvement |
---|---|---|---|
Lines of Code | ~120 | ~250 | 52% reduction |
Setup Time | 5 minutes | 25 minutes | 80% reduction |
Error Handling | Built-in retries | Manual implementation | Simplified |
Maintainability | High | Medium | Easier to maintain |
You can extend this example by: