Search code examples
apiduplicatesjson-apihttp-response-codesruby-on-rails-5

JSON:API HTTP status code for duplicate content creation avoidance


Suppose I have an endpoint that supports creating new messages. I am avoiding the creation of two times the same message in the backend, in case the user tries to push the button twice (or in case the frontend app behaves strangely).

Currently for the duplicate action my server is responding with a 303 see other pointing to the previously created resource URL. But I see I could also use a 302 found. Which one seems more appropriate ?

Note that the duplicate avoidance strategy can be more complex (eg for an appointment we would check whether the POSTed appointment is within one hour of an existing one)


Solution

  • I recommend using HTTP Status Code 409: Conflict.