Last post Jan 17, 2014 04:21 AM by PatriceSc
Jan 16, 2014 03:39 PM|SandeepC.ST|LINK
Whay doesn't a method decorated with HttpPost attribute return status code os 201?
Jan 16, 2014 06:48 PM|PatriceSc|LINK
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html , 201 is "The request has been fulfilled and resulted in a new resource being created". But also "The newly created resource can be referenced by the URI(s) returned in the entity of the response,
with the most specific URI for the resource given by a Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate."
So it seems better to just use the simpler 200 OK by default and let a developper to implement 201 if he really wants rather than to enforce those more specific requirements (how ?) by default as soon as you use a POST request and still have to give him
a way to opt-in for something that is actually simpler...
Jan 16, 2014 11:01 PM|SandeepC.ST|LINK
Jan 17, 2014 04:21 AM|PatriceSc|LINK
"let the rest be done by the developper"
If you want to implement 201, this is exactly what you can do right now.
If it was the default then you would be "forced" either to implement this so that it meets the 201 requirements or you would have to explicity opt-out of this to revert back to the simplest 200 OK case. More likely we would see tons of incorrect 201 responses.
At this point it seems just a question of logic. You do have the more general, simplest, most often used case by default and you can still use 201 if you really want to. It would seems a weird idea to default to the more complex, less used case by default
(not even being able to have really that without having the developer to do the proper things) and have to do something to switch to the simplest, mostly used case ???
Edit : so if you want 201 just check
http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations and scroll down to creating a resource...