0
0
Rest APIprogramming~10 mins

409 Conflict 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 the correct HTTP status code for a conflict error.

Rest API
return Response(status=[1])
Drag options to blanks, or click blank then click option'
A200
B409
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means not found instead of conflict.
Using 200 which means success instead of an error code.
2fill in blank
medium

Complete the code to check if a resource exists and return a 409 Conflict if it does.

Rest API
if resource_exists:
    return Response(status=[1])
Drag options to blanks, or click blank then click option'
A409
B400
C403
D201
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 201 Created when resource already exists.
Using 400 Bad Request instead of 409 Conflict.
3fill in blank
hard

Fix the error in the code to correctly return a 409 Conflict with a JSON message.

Rest API
return Response({"error": "Conflict detected"}, status=[1])
Drag options to blanks, or click blank then click option'
A409
B500
C404
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 Not Found instead of 409 Conflict.
Using 200 OK which means success.
4fill in blank
hard

Fill both blanks to create a response that returns 409 Conflict with a JSON error message.

Rest API
return Response({"message": [1], status=[2])
Drag options to blanks, or click blank then click option'
A"Resource already exists"
B409
C404
D"Not found"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 status code instead of 409.
Using a message that does not explain the conflict.
5fill in blank
hard

Fill all three blanks to handle a POST request that returns 409 Conflict if the user exists.

Rest API
def create_user(data):
    if [1](data['username']):
        return Response([2]: [3], status=409)
    # create user logic here
Drag options to blanks, or click blank then click option'
Auser_exists
B"error"
C"User already exists"
Dcreate_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong function name to check user existence.
Using incorrect JSON keys or messages.
Not returning status 409 for conflict.