alexandrialibrary / Alexandria

Alexandria is a simple little card catalogue webapp with a terribly pretentious name.
MIT License
2 stars 1 forks source link

POST response for objects that already exist #68

Open hawkw opened 9 years ago

hawkw commented 9 years ago

What should the POST /books/ and POST /authors/ routes return when the entity POSTed already exists in the database?

This should be added to the API spec.

hawkw commented 9 years ago

StackOverflow suggests either 409 Conflict or the WebDAV extension 422 Unprocessable Entity. Since we're already returning 409 Conflict in the Loans API when creating loans that already exist, I'm thinking that might be the right choice.

hawkw commented 9 years ago

Of course, there's also the option of using multiple POSTs to update an entry, but my understanding of HTTP verb semantics is that it's best to use PUT for that.

hawkw commented 9 years ago

It's worth noting that Scalatra does have support for the PUT and DELETE verbs, and that there is a 422 ActionResult. So those wouldn't take any extra work to do.

hawkw commented 9 years ago

I'm going to just go ahead and decide to return 422. If @redbassett thinks this is incorrect or would prefer different behaviour, we can change it.

hawkw commented 9 years ago

Fixed in 5b0e2166f34250ca0b8355e22e40522eb416eb03 and 3b6556e426474f64b981a6d647f2b18cc435fdcc on develop.