Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a deprecation warning header in the API response.
Rest API
response.headers['[1]'] = 'This API endpoint is deprecated and will be removed soon.'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using standard headers like 'Content-Type' or 'Authorization' for deprecation messages.
✗ Incorrect
The 'X-Deprecation-Warning' header is commonly used to inform clients that the API endpoint is deprecated.
2fill in blank
mediumComplete the code to set the deprecation date in the response header.
Rest API
response.headers['Deprecation-Date'] = '[1]'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-standard date formats that can confuse clients.
✗ Incorrect
The ISO 8601 format 'YYYY-MM-DD' is the standard for date headers in APIs.
3fill in blank
hardFix the error in the code to correctly add a deprecation notice in JSON response.
Rest API
return [1](jsonify({'message': 'Deprecated endpoint'}), 299)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jsonify' alone with a status code, which causes errors.
✗ Incorrect
The 'make_response' function wraps the JSON and status code properly for Flask responses.
4fill in blank
hardFill both blanks to add a deprecation warning and set the warning header in the response.
Rest API
response = [1](jsonify({'warning': 'Deprecated API'})) response.headers['[2]'] = 'Use new API version'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jsonify' directly without wrapping in 'make_response'.
Setting standard headers instead of the deprecation warning header.
✗ Incorrect
Use 'make_response' to create the response object and set 'X-Deprecation-Warning' header for deprecation notice.
5fill in blank
hardFill all three blanks to create a JSON response with a deprecation message, set status code 299, and add a deprecation header.
Rest API
resp = [1](jsonify({'message': [2]), [3]) resp.headers['X-Deprecation-Warning'] = 'Deprecated endpoint'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jsonify' instead of 'make_response' to set status code.
Not quoting the message string.
Using wrong status code.
✗ Incorrect
Use 'make_response' to wrap the JSON message with status code 299 and add the deprecation header.