ocngx / quick_start.py
tanbushi's picture
update
5e15438
Raw
History Blame
1.91 kB
#!/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()