Bird
0
0

In a REST API, if a POST request creates a resource but the client sends duplicate data, what is the best practice for the status code?

hard📝 Application Q9 of 15
Rest API - HTTP Status Codes
In a REST API, if a POST request creates a resource but the client sends duplicate data, what is the best practice for the status code?
A409 Conflict indicating duplicate
B200 OK with existing resource data
C204 No Content
D201 Created with Location header
Step-by-Step Solution
Solution:
  1. Step 1: Understand duplicate resource creation and identify correct status code

    If the resource already exists, the server should inform the client about the conflict. 409 Conflict is used to indicate duplicate or conflicting resource creation attempts.
  2. Final Answer:

    409 Conflict indicating duplicate -> Option A
  3. Quick Check:

    Duplicate creation returns 409 Conflict [OK]
Quick Trick: Use 409 Conflict for duplicate resource creation attempts [OK]
Common Mistakes:
MISTAKES
  • Returning 201 Created for duplicates
  • Using 200 OK without conflict info
  • Ignoring duplicate detection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes