0
0
Rest APIprogramming~10 mins

404 Not Found 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 404 Not Found status in a REST API response.

Rest API
return Response(status=[1])
Drag options to blanks, or click blank then click option'
A404
B500
C302
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 which means success instead of 404.
Using 500 which means server error instead of 404.
2fill in blank
medium

Complete the code to check if a resource exists and return 404 if not found.

Rest API
if resource is None:
    return [1](status=404)
Drag options to blanks, or click blank then click option'
AResponse
Bredirect
Cprint
Draise
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of returning a response.
Using raise without specifying an exception.
3fill in blank
hard

Fix the error in the code to correctly return a 404 Not Found JSON response.

Rest API
return Response({"error": "Not found"}, status=[1])
Drag options to blanks, or click blank then click option'
A200
B404
C400
D201
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 which means success.
Using 400 which means bad request.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps resource names to 404 if missing.

Rest API
missing_resources = {name: [1] for name in resources if resources[name] [2] None}
Drag options to blanks, or click blank then click option'
A404
B==
C!=
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' to check for None.
Using None as the value instead of 404.
5fill in blank
hard

Fill all three blanks to filter and return 404 for missing items in a dictionary.

Rest API
result = [1]({key: value for key, value in data.items() if value [2] None and value [3] ''})
Drag options to blanks, or click blank then click option'
Adict
B!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' in conditions.
Not wrapping comprehension with dict().