Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to make 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' when only retrieving data.
Using 'put' or 'delete' which are for updating or deleting data.
✗ Incorrect
The get method sends a GET request to the specified URL to retrieve data.
2fill in blank
mediumComplete the code to print the status code of the API response.
Rest API
print(response.[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' or 'content' which contain the response body, not the status code.
Using 'json' which parses the response body, not the status code.
✗ Incorrect
The status_code attribute shows the HTTP status code returned by the API.
3fill in blank
hardFix the error in the code to parse the 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' or 'content' which return raw strings or bytes.
Using 'status_code' which is an integer, not the response body.
✗ Incorrect
The json() method parses the response body as JSON and returns a Python dictionary.
4fill in blank
hardFill both blanks to check if the response status code is 200 and print success.
Rest API
if response.[1] == [2]: print('Success!')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing the response text to '200' instead of the status code.
Using 'json' or 'text' instead of 'status_code' for the check.
✗ Incorrect
Check if response.status_code equals 200 which means the request was successful.
5fill in blank
hardFill both blanks to extract the 'name' field from the JSON response and print it.
Rest API
data = response.[1]() name = data[[2]] print(name)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'json' to parse the response.
Accessing the wrong key like 'id' instead of 'name'.
✗ Incorrect
Use json() to parse the response, then access the 'name' key to get the value.