Reputation: 5867
I am trying to access a REST enpoint that adds a book in bookshelf location.
PUT /bookshelf/books/1
HTTP/1.1 201 Created
Now if I try to add book again with id 1
PUT /bookshelf/books/1
HTTP/1.1 500 Internal server error
I get 500 Internal server error, with the response message
"Resource already exists, cannot add duplicate item"
Now this looks wrong to me. Is this a right kind of response to expect from the server. Considering the operation is PUT, I feel the clients should feel free to run the PUT invocations to do again and again. Is my understanding correct?
If not 500
should the server just return HTTP/1.1 200 OK
?
Upvotes: 1
Views: 857
Reputation: 4048
PUT is idempotent - if you call it multiple times you should get the same result. i.e. the object is created/updated as per your request. Returning 500 to a PUT request because the object already exists goes against RESTful semantics. I would also expect 200 back in this instance.
Upvotes: 1