Complete the code to send a GET request to the API endpoint.
response = requests.[1]('https://api.example.com/data')
The GET method is used to retrieve data from the API, which is essential for validating the contract.
Complete the code to check if the response status code is 200 (OK).
if response.status_code == [1]:
Status code 200 means the request was successful, confirming the API contract is met.
Fix the error in the code to parse JSON response correctly.
data = response.[1]()Using response.json() parses the response body as JSON, which is needed to validate the contract data.
Fill both blanks to check if the response contains the expected key and its value is correct.
if '[1]' in data and data['[2]'] == 'success':
The contract expects a 'status' key with value 'success' to confirm correct API behavior.
Fill all three blanks to create a dictionary comprehension that extracts user IDs for active users.
active_users = {user['[1]']: user['[2]'] for user in data['[3]'] if user['active']}This comprehension builds a dictionary of user IDs and names for users marked active, validating the contract's data structure.