0
0
Rest APIprogramming~10 mins

Why testing validates contracts in Rest API - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a GET request to the API endpoint.

Rest API
response = requests.[1]('https://api.example.com/data')
Drag options to blanks, or click blank then click option'
Aget
Bput
Cpost
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET to retrieve data.
2fill in blank
medium

Complete the code to check if the response status code is 200 (OK).

Rest API
if response.status_code == [1]:
Drag options to blanks, or click blank then click option'
A500
B404
C200
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 404 instead of 200.
3fill in blank
hard

Fix the error in the code to parse JSON response correctly.

Rest API
data = response.[1]()
Drag options to blanks, or click blank then click option'
Atext
Bjson
Ccontent
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text instead of response.json().
4fill in blank
hard

Fill both blanks to check if the response contains the expected key and its value is correct.

Rest API
if '[1]' in data and data['[2]'] == 'success':
Drag options to blanks, or click blank then click option'
Astatus
Berror
Cmessage
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' or 'message' instead of 'status'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that extracts user IDs for active users.

Rest API
active_users = {user['[1]']: user['[2]'] for user in data['[3]'] if user['active']}
Drag options to blanks, or click blank then click option'
Aid
Bname
Cusers
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'users' for the list key.