Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' will try to create data instead of retrieving it.
✗ Incorrect
The get method sends a GET request to retrieve data from the API.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 means 'Not Found', which is an error.
✗ Incorrect
Status code 200 means the request was successful.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' returns raw string, not parsed JSON.
✗ Incorrect
The json() method parses the response body as JSON.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST will not send data.
Providing incorrect JSON data format.
✗ Incorrect
Use post to send data and provide the JSON payload as a dictionary.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text()' instead of 'json()' to parse response.
Using wrong key name or comparison operator.
✗ Incorrect
Parse JSON, get the 'id' field, and check it is greater than zero.