# {{ zone_name | title }} API Client

Generated Python HTTP client for {{ zone_name }} zone using Django Revolution.

## Features

- ✅ **Full HTTP Client**: Complete HTTP client with retry logic and error handling
- ✅ **Generated Models**: Pydantic models for all API endpoints
- ✅ **Type Safety**: Full type hints and validation
- ✅ **Authentication**: Built-in token-based authentication
- ✅ **Retry Logic**: Automatic retry on network errors
- ✅ **Response Wrapping**: Clean response objects with status checking

## Installation

```bash
pip install pydantic requests
```

## Quick Start

```python
from http_client import {{ zone_name }}_client

# Create client
client = {{ zone_name }}_client("http://localhost:8000")

# Make API calls
response = client.get("{{ zone_name }}/")
if response.is_success():
    print(response.data)
```

## Usage

### Basic API Calls

```python
from http_client import {{ zone_name }}_client

# Initialize client
client = {{ zone_name }}_client("http://localhost:8000")

# GET request
response = client.get("{{ zone_name }}/")
if response.is_success():
    data = response.data
    print(f"Response: {data}")

# POST request
data = {"name": "new_item", "description": "Test item"}
response = client.post("{{ zone_name }}/items/", data=data)
if response.is_success():
    print("Item created successfully")

# PUT request
update_data = {"description": "Updated description"}
response = client.put("{{ zone_name }}/items/1/", data=update_data)

# DELETE request
response = client.delete("{{ zone_name }}/items/1/")
```

### Using Generated Models

```python
from models import *

# Create model instance (adjust based on your actual models)
# Example: Create a request model
if 'PostRequest' in globals():
    post_request = PostRequest(
        title="Test Post",
        content="Test content",
        published=True
    )

    # POST with model data
    response = client.post("{{ zone_name }}/posts/", data=post_request.model_dump())

    # Parse response into model
    if response.is_success():
        post = Post(**response.data)
        print(f"Created post: {post.title}")
```

### Authentication

```python
# Set authentication token
client.set_auth_token("your-jwt-token-here")

# Make authenticated request
response = client.get("{{ zone_name }}/protected-endpoint/")

# Clear token when done
client.clear_auth_token()
```

### Error Handling

```python
try:
    response = client.get("{{ zone_name }}/items/")
    if response.is_success():
        print("Request successful")
    else:
        print(f"Request failed: {response.status_code}")
        print(f"Error: {response.data}")
except Exception as e:
    print(f"Network error: {e}")
```

### Advanced Configuration

```python
from http_client import {{ zone_name | title }}Config, {{ zone_name | title }}Client

# Custom configuration
config = {{ zone_name | title }}Config(
    base_url="https://api.example.com",
    api_prefix="/api/v1/",
    timeout=60,
    max_retries=5,
    headers={"X-Custom-Header": "value"},
    auth_token="your-token"
)

# Create client with custom config
client = {{ zone_name | title }}Client(config)
```

## API Endpoints

This client provides access to all endpoints in the {{ zone_name }} zone.

## Generated Models

The following Pydantic models are available in `models.py`:

- All models from your API schema

## Configuration

### {{ zone_name | title }}Config

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `base_url` | str | "http://localhost:8000" | Base URL for API |
| `api_prefix` | str | "/api/" | API path prefix |
| `timeout` | int | 30 | Request timeout in seconds |
| `max_retries` | int | 3 | Maximum retry attempts |
| `headers` | Dict[str, str] | {} | Custom headers |
| `auth_token` | str | None | Authentication token |

### {{ zone_name | title }}Response

| Property | Type | Description |
|----------|------|-------------|
| `response` | requests.Response | Raw requests response |
| `data` | Any | Parsed response data |
| `status_code` | int | HTTP status code |
| `headers` | Dict[str, str] | Response headers |
| `url` | str | Request URL |

## Development

This client was generated by Django Revolution. To regenerate:

```bash
python manage.py revolution --generate --zones {{ zone_name }}
```

## License

Generated by Django Revolution. 