0
0
Rest APIprogramming~10 mins

200 OK and 201 Created 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 200 OK status in a REST API response.

Rest API
return Response(status=[1])
Drag options to blanks, or click blank then click option'
A404
B201
C500
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 201 instead of 200 for a successful GET request.
Using 404 or 500 which indicate errors.
2fill in blank
medium

Complete the code to return a 201 Created status after successfully creating a resource.

Rest API
return Response(status=[1])
Drag options to blanks, or click blank then click option'
A201
B204
C200
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 201 after creating a resource.
Using 204 which means no content returned.
3fill in blank
hard

Fix the error in the code to correctly return a 201 Created status with a JSON body.

Rest API
return Response({"id": new_id}, status=[1])
Drag options to blanks, or click blank then click option'
A201
B200
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 200 instead of 201 after resource creation.
Using error codes like 404 or 500 incorrectly.
4fill in blank
hard

Fill both blanks to create a response with 201 status and a Location header pointing to the new resource URL.

Rest API
return Response(status=[1], headers={{'Location': [2])
Drag options to blanks, or click blank then click option'
A201
B200
C"/items/123"
D"/home"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 status instead of 201 for creation.
Setting Location header to an unrelated URL.
5fill in blank
hard

Fill all three blanks to return a 200 OK response with JSON data and a custom header.

Rest API
return Response([1], status=[2], headers={{'X-Custom': [3])
Drag options to blanks, or click blank then click option'
A{"message": "Success"}
B200
C"Value123"
D"/new-resource"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 201 status when no resource was created.
Passing non-string values in headers.