| |
| """ |
| Quick Start Demo for OpenResty API Client |
| |
| This script demonstrates the most common usage patterns for the API client. |
| """ |
|
|
| from api_client import create_client, APIClientError, AuthenticationError |
|
|
| def main(): |
| print("π OpenResty API Client - Quick Start Demo") |
| print("=" * 50) |
| |
| |
| print("\n1. Creating API client...") |
| client = create_client() |
| |
| try: |
| |
| print("\n2. Testing main endpoint...") |
| response = client.get("/") |
| print(f" β
Status: {response['status']}") |
| print(f" β
Status Code: {response['status_code']}") |
| print(f" β
Content-Type: {response['headers'].get('Content-Type')}") |
| |
| |
| print("\n3. Testing health check...") |
| health = client.health_check() |
| print(f" β
Health Status: {health['status']}") |
| print(f" β
Health Message: {health['message']}") |
| |
| |
| print("\n4. Authentication Info:") |
| print(f" β
Server: {response['headers'].get('server')}") |
| print(f" β
X-Powered-By: {response['headers'].get('x-powered-by')}") |
| print(f" β
X-Auth-Type: {response['headers'].get('x-auth-type')}") |
| |
| print("\nπ All tests passed! Your API client is working correctly.") |
| |
| except AuthenticationError as e: |
| print(f"β Authentication failed: {e.message}") |
| print(" Please check your credentials.") |
| |
| except APIClientError as e: |
| print(f"β API error: {e.message}") |
| |
| except Exception as e: |
| print(f"β Unexpected error: {e}") |
| |
| finally: |
| |
| client.close() |
| print("\nπ Client session closed.") |
|
|
| if __name__ == "__main__": |
| main() |