3

Just wondering what HTTP status code I should return for a REST api if the posted data already exists. Example if I have a create account API that requires an email.

1) If this email already exists on my DB, what status code should I return?

2) If I redirect to another page, like an existing account login page, should the status code then be 200? or 300 for redirection?

If this question has been answered, please just give me the link and I can delete this, but so far I only saw questions for invalid data.

ibaralf
  • 12,218
  • 5
  • 47
  • 69
  • [HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses) is a great place IMO. – Ravi Anand Nov 30 '21 at 15:41

1 Answers1

5

This post suggests to use the 409 Conflict status code when duplicated data is submitted.

Community
  • 1
  • 1
ebo
  • 2,717
  • 1
  • 27
  • 22
  • But what if I don't expect user to re-submit the request. It's just that operation is not supported on existing resource? – Harish Apr 13 '16 at 10:53
  • That would probably be a 405, see: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html – ebo Apr 17 '16 at 11:54