api-testing-patternslisted
Install: claude install-skill Izangi2714/claude-code-python-stack
# API Testing Patterns
Production patterns for API test automation with httpx, requests, Pydantic, and pytest.
## When to Activate
- Writing HTTP API tests (REST, GraphQL)
- Building reusable HTTP client wrappers
- Validating API responses against schemas
- Generating test data with factories
- Implementing retry/polling for async operations
- Setting up contract testing
## HTTP Client: httpx (Recommended)
### Why httpx over requests
| Feature | httpx | requests |
|---------|-------|----------|
| Async support | Native | No |
| HTTP/2 | Yes | No |
| Timeout config | Granular | Basic |
| Connection pooling | Built-in | Built-in |
| Type hints | Full | Partial |
| API compatibility | requests-like | N/A |
### Client Wrapper
```python
import httpx
import allure
import logging
from framework.config.settings import Settings
logger = logging.getLogger(__name__)
class HTTPClient:
def __init__(self, settings: Settings, token: str | None = None):
headers = {"Content-Type": "application/json", "Accept": "application/json"}
if token:
headers["Authorization"] = f"Bearer {token}"
self._client = httpx.Client(
base_url=settings.BASE_URL,
headers=headers,
timeout=httpx.Timeout(
connect=5.0,
read=settings.REQUEST_TIMEOUT,
write=5.0,
pool=5.0,
),
)
@allure.step("{method} {url}")
def request(self, method: str, url: s