<!--
title: Optimize API consumption
domain: orchestration
topic: API
language: Yaml
source: temporalio/temporal
updated: 2025-04-24
url: https://awesomereviewers.com/reviewers/temporal-optimize-api-consumption/
-->

When interacting with APIs, minimize network requests and improve code maintainability by:
1. Extracting repetitive API call patterns into reusable functions
2. Retrieving multiple data points with a single API call when possible

Example:
```bash
# Create a reusable function for API calls
call() {
  curl -fL -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $PAT" "$@"
}

# Use the function and make a single API call to get multiple pieces of data
result=$(call "https://api.github.com/repos/$PARENT_REPO/actions/runs/$run_id")
status=$(echo "$result" | jq -r .status)
conclusion=$(echo "$result" | jq -r .conclusion)
```
