Python `requests` Code

The Python code below calls a real API. The "Live Tester" on the right **simulates** this API's response directly in your browser.

import requests

# This URL would point to a real server-side script
url = 'https://bayujunisp.pythonanywhere.com/api/apiautomation'

# --- Case 1: Successful Request ---
success_payload = {
    'id': '1010',
    'name': 'Lionel Messi',
    'email': 'messi@intermiami.com'
}
response = requests.post(url, data=success_payload)
print(f"Status Code: {response.status_code}")
print("Response JSON:", response.json())


# --- Case 2: Failed Request (missing 'email') ---
# failed_payload = {
#     'id': '007',
#     'name': 'Cristiano Ronaldo'
# }
# response = requests.post(url, data=failed_payload)
# print(f"Status Code: {response.status_code}")
# print("Response JSON:", response.json())

Live API Tester (Simulated)

Success Response

{
    "status": "success",
    "message": "Data received successfully.",
    "data": {
        "id": "1010",
        "name": "Li101onel Messi",
        "email": "messi@intermiami.com"
    }
}

Failed Response

{
    "status": "error",
    "message": "Missing required fields: email"
}

Python `requests` in a Loop

This Python code calls a real API in a loop. The "Live Tester" on the right simulates this behavior.

import requests

url = 'https://bayujunisp.pythonanywhere.com/api/apiautomation'

users_to_add = [
    {'id': '0071', 'name': 'David Beckam', 'email': 'beckam@manchesteru.com'},
    {'id': '0072', 'name': 'Eric Cantona', 'email': 'eric@manchesteru.com'},
    {'id': '0081', 'name': 'Paul Scholes', 'email': 'scholes@manchesteru.com'},
    {'id': '0074', 'name': 'Cristiano Ronaldo'} # This one will fail
]

for user in users_to_add:
    print(f"--- Sending data for {user.get('name', 'N/A')} ---")
    response = requests.post(url, data=user)
    print(f"Status: {response.status_code}")
    print(f"Response: {response.json()}\n")

Live Loop Tester (Simulated)

Click the button below to send 4 API requests in a sequence (the last one is designed to fail).

API Responses

Click the button to see the responses...