0
0
Rest APIprogramming~10 mins

Graceful degradation 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 return a fallback message when the main API call fails.

Rest API
response = call_main_api()
if not response:
    return [1]
Drag options to blanks, or click blank then click option'
Aresponse.json()
B"Success"
C"Service unavailable, please try later."
Dcall_backup_api()
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the original response without checking if it failed.
Calling the main API again instead of returning a fallback message.
2fill in blank
medium

Complete the code to call a backup API if the main API call fails.

Rest API
response = call_main_api()
if not response:
    response = [1]
Drag options to blanks, or click blank then click option'
ANone
Bcall_main_api()
Creturn "Error"
Dcall_backup_api()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the main API again instead of the backup.
Returning an error message instead of trying the backup.
3fill in blank
hard

Fix the error in the code to handle API failure gracefully.

Rest API
try:
    data = call_main_api()
except Exception:
    data = [1]
Drag options to blanks, or click blank then click option'
Acall_backup_api()
Braise
CNone
Dprint('Error')
Attempts:
3 left
💡 Hint
Common Mistakes
Re-raising the exception instead of handling it.
Setting data to None without fallback.
4fill in blank
hard

Fill both blanks to create a dictionary with API data or fallback values.

Rest API
result = {
    "status": [1],
    "data": [2]
}
Drag options to blanks, or click blank then click option'
A"success"
Bcall_main_api()
CNone
D"failed"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function call directly instead of a string for status.
Setting data to a string instead of None.
5fill in blank
hard

Fill all three blanks to build a graceful degradation response dictionary.

Rest API
response = {
    "status": [1],
    "message": [2],
    "data": [3]
}
Drag options to blanks, or click blank then click option'
A"error"
B"Service temporarily unavailable"
CNone
D"success"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' status when there is an error.
Providing data instead of None when service is down.