0
0
Rest APIprogramming~10 mins

Integration testing in Rest API - Interactive Code Practice

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 = client.[1]('/api/users')
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' will try to create data instead of retrieving it.
2fill in blank
medium

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

Rest API
assert response.status_code == [1]
Drag options to blanks, or click blank then click option'
A200
B201
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 means 'Not Found', which is an error.
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'
Acontent
Btext
Cjson
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' returns raw string, not parsed JSON.
4fill in blank
hard

Fill both blanks to send a POST request with JSON data and check the status code.

Rest API
response = client.[1]('/api/users', json=[2])
assert response.status_code == 201
Drag options to blanks, or click blank then click option'
Apost
B{'name': 'Alice'}
C{'id': 1}
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST will not send data.
Providing incorrect JSON data format.
5fill in blank
hard

Fill all three blanks to extract the user ID from the JSON response and verify it is greater than zero.

Rest API
data = response.[1]()
user_id = data[[2]]
assert user_id [3] 0
Drag options to blanks, or click blank then click option'
Ajson
B'id'
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text()' instead of 'json()' to parse response.
Using wrong key name or comparison operator.