1

In my ASP.NET WEB API controller, I have exposed actions equivalent to the HTTP verbs :- Post, Put, Get and Delete, as follows:-

  1. PostLocation
  2. PutLocation
  3. DeleteLocation
  4. GetLocation
  5. GetAllLocations

The following are the clarifications I need in this regard :-

  1. When Post is used to create a location, and the location already exists, Should I consider it as a PUT operation and modify the resource (or) Return an response code indicating that the resource already exists.

  2. In case i need to return an response code indicating that the resource already exists, then what is the correct HTTPResponseCode that should be used and what should be given in the response body?

Proper directions regarding the best practices for the recommended HTTPResponse codes for RESTFUL Web APIs are highly appreciated.

LCJ
  • 22,196
  • 67
  • 260
  • 418
PRN
  • 189
  • 2
  • 9

1 Answers1

1

Please try this question.

And These are return code

Community
  • 1
  • 1
Sarbanjeet
  • 253
  • 1
  • 15
  • 409 Conflict - For POST / PUT requests if the resource already exists. – Sarbanjeet Feb 08 '14 at 06:22
  • The link also states to use the code :- 303 See Other. But I feel 409 would be more ideal. Will it also be ideal to return the Uri to the already existing resource in the response body? – PRN Feb 08 '14 at 06:34
  • Makes sense for a POST request. But ideally a PUT request, which is equivalent to an Update action, the expectation is to have the resource already exists, right? . So why should I return a 409 in such a case? The new entity being passed should replace the existing entity for a PUT with the ID already existing. Please correct me if I am wrong. – PRN Feb 08 '14 at 06:41
  • [link 1](http://stackoverflow.com/questions/17076349/edit-conflicts-and-409-vs-412-responses) [Link2](http://stackoverflow.com/questions/11257470/is-returning-http-409-appropriate-for-a-validation-check) [All you need](http://stackoverflow.com/questions/19122088/which-http-status-code-to-use-to-reject-a-put-due-to-optimistic-locking-failure) – Sarbanjeet Feb 08 '14 at 06:49
  • Thanks. Will check those links and use the appropriate codes. – PRN Feb 08 '14 at 06:57