-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
48 lines (43 loc) · 1.66 KB
/
test_api.py
File metadata and controls
48 lines (43 loc) · 1.66 KB
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
import requests
import json
BASE_URL = "http://localhost:5000"
print("=" * 70)
print("EXAMPLE 1: Fetch 2 users from United States (US)")
print("=" * 70)
response = requests.get(f"{BASE_URL}/api/users?results=2&nat=US")
data = response.json()
for user in data['users']:
print(f"Name: {user['first_name']} {user['last_name']}")
print(f"Email: {user['email']}")
print(f"Location: {user['city']}, {user['state']}, {user['country']}")
print(f"Nationality: {user['nationality']}")
print("-" * 70)
print("\n" + "=" * 70)
print("EXAMPLE 2: Fetch 2 users from India (IN)")
print("=" * 70)
response = requests.get(f"{BASE_URL}/api/users?results=2&nat=IN")
data = response.json()
for user in data['users']:
print(f"Name: {user['first_name']} {user['last_name']}")
print(f"Email: {user['email']}")
print(f"Location: {user['city']}, {user['state']}, {user['country']}")
print(f"Nationality: {user['nationality']}")
print("-" * 70)
print("\n" + "=" * 70)
print("EXAMPLE 3: Fetch 2 female users from United Kingdom (GB)")
print("=" * 70)
response = requests.get(f"{BASE_URL}/api/users?results=2&gender=female&nat=GB")
data = response.json()
for user in data['users']:
print(f"Name: {user['first_name']} {user['last_name']}")
print(f"Email: {user['email']}")
print(f"Gender: {user['gender']}")
print(f"Location: {user['city']}, {user['state']}, {user['country']}")
print(f"Nationality: {user['nationality']}")
print("-" * 70)
print("\n" + "=" * 70)
print("EXAMPLE 4: Raw JSON response from France (FR)")
print("=" * 70)
response = requests.get(f"{BASE_URL}/api/users?results=1&nat=FR")
data = response.json()
print(json.dumps(data, indent=2))