File size: 1,909 Bytes
5e15438 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #!/usr/bin/env python3
"""
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)
# Create client using convenience function
print("\n1. Creating API client...")
client = create_client()
try:
# Test main endpoint
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')}")
# Test health check
print("\n3. Testing health check...")
health = client.health_check()
print(f" β
Health Status: {health['status']}")
print(f" β
Health Message: {health['message']}")
# Display authentication info from headers
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:
# Always close the client
client.close()
print("\nπ Client session closed.")
if __name__ == "__main__":
main() |