Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a POST request to the API endpoint.
Prompt Engineering / GenAI
response = requests.[1]('https://api.example.com/predict', json=data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST causes the server to not receive data.
Using PUT or DELETE when only POST is accepted.
✗ Incorrect
The POST method is used to send data to the API for prediction.
2fill in blank
mediumComplete the code to extract the JSON response from the API call.
Prompt Engineering / GenAI
result = response.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text returns raw string, not parsed JSON.
Using response.status_code returns the HTTP status, not data.
✗ Incorrect
The json() method parses the response content as JSON.
3fill in blank
hardFix the error in the code to handle API errors properly.
Prompt Engineering / GenAI
if response.status_code != [1]: print('Error:', response.status_code)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 404 or 500 instead of 200 causes false error detection.
Using 201 which means resource created, not general success.
✗ Incorrect
Status code 200 means the request was successful.
4fill in blank
hardFill both blanks to prepare headers and send the API request with authentication.
Prompt Engineering / GenAI
headers = {'Authorization': 'Bearer [1]'}
response = requests.post(url, json=data, headers=[2]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data instead of headers causes authentication failure.
Using wrong token string in Authorization header.
✗ Incorrect
The Authorization header needs the token, and headers must be passed as the headers argument.
5fill in blank
hardComplete the code to parse the prediction from the API response dictionary.
Prompt Engineering / GenAI
prediction = result['output'[1]0]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets causes errors.
Missing brackets leads to wrong data access.
✗ Incorrect
Access the 'output' key with [ ] and then the first element with [0].