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()