Skip to content

Conversation

@kaxil
Copy link
Collaborator

@kaxil kaxil commented Jan 31, 2026

Summary

Add a generic af api command that provides direct access to any Airflow REST API endpoint, similar to gh api for GitHub. This enables users and AI agents to access any API endpoint not covered by the high-level CLI commands.

Features

  • HTTP Methods: GET, POST, PATCH, PUT, DELETE via -X flag
  • Query Parameters: -F key=value (auto type conversion) or -f key=value (raw string)
  • JSON Body: --body '{...}' for complex payloads
  • Endpoint Discovery: --endpoints lists available paths, --filter narrows results
  • OpenAPI Spec: --spec fetches full API spec
  • Response Headers: -i includes status code and headers
  • Raw Endpoints: --raw bypasses version prefix (for /health, etc.)
  • Version Handling: Automatic AF2 (/api/v1) vs AF3 (/api/v2) detection

Usage Examples

# Discover available endpoints
af api --endpoints
af api --endpoints --filter variable

# Basic operations
af api dags
af api dags -F limit=10 -F only_active=true
af api dags/my_dag

# Create/modify resources
af api variables -X POST -F key=my_var -f value="my value"
af api dags/my_dag -X PATCH -F is_paused=false
af api variables/old_var -X DELETE

# Debug with headers
af api dags -i

# Access non-versioned endpoints
af api health --raw

Design Decisions

Why add to adapter vs direct HTTP?
The adapter pattern already handles authentication (token/basic auth via _setup_auth()) and version prefixes. Adding raw_request() to the base adapter keeps the architecture consistent.

Why --endpoints instead of requiring jq?
Not all users have jq installed, and endpoint discovery is a common operation. The --filter option makes it easy to find specific endpoints without external tools.

Why warn on connections endpoint?
Unlike af config connections which filters passwords, af api connections returns raw API responses. The warning directs users to the filtered alternative.

Files Changed

File Change
adapters/base.py Add raw_request() and _delete() methods
cli/api.py New command module (357 lines)
cli/main.py Register the command
tests/test_cli_api.py Unit tests (34 tests)
tests/integration/test_cli_api.py Integration tests (17 tests)
README.md Document the command
skills/airflow/SKILL.md Add quick reference
skills/airflow/api-reference.md Full reference (progressive disclosure)

kaxil added 2 commits January 31, 2026 00:24
Add a generic `af api` command that provides direct access to any Airflow
REST API endpoint, similar to `gh api` for GitHub.

Features:
- HTTP methods: GET, POST, PATCH, PUT, DELETE via `-X` flag
- Query parameters via `-F key=value` (auto type conversion) or `-f key=value` (raw string)
- JSON body support via `--body '{...}'`
- Endpoint discovery via `--endpoints` and `--endpoints --filter <pattern>`
- Full OpenAPI spec via `--spec`
- Include response headers via `-i`
- Raw endpoint access (bypass version prefix) via `--raw`
- Automatic AF2/AF3 version handling via adapter's `api_base_path`
- Security warning when accessing connection endpoints

Implementation:
- Add `raw_request()` method to base adapter for generic HTTP calls
- Add `_delete()` method to base adapter
- New `cli/api.py` module with the command implementation
- Unit tests (34 tests) and integration tests (17 tests)

Documentation:
- Update README with `af api` examples
- Add `api-reference.md` skill reference file
- Update Airflow skill with endpoint discovery patterns
@kaxil kaxil requested review from jlaneve, milton-li and schnie and removed request for schnie January 31, 2026 00:26
@kaxil kaxil merged commit bc4f681 into main Jan 31, 2026
10 checks passed
@kaxil kaxil deleted the feat/af-api-command branch January 31, 2026 00:48
@jlaneve
Copy link
Collaborator

jlaneve commented Jan 31, 2026

@kaxil wdyt about af api ls or something instead of the af api --endpoints? the flag feels a bit odd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants