[99s-extend] PUT on new resource and status 201

Loïc Hoguin essen at ninenines.eu
Tue Oct 14 12:38:08 CEST 2014


Hi,

On 10/14/2014 10:05 AM, Stefan Strigler wrote:
> I'm referring to
> http://ninenines.eu/docs/en/cowboy/1.0/guide/rest_flowcharts/. Given you
> have a PUT on a new resource the diagram suggests that the response's
> status code depends on whether you've set a location and/or body. But
> when looking at the code (v1.0.0) then cowboy_rest:maybe_created/2 would
> always return a 201. No matter what. I think the code is right, but the
> diagram needs to be fixed.

Yes it looks like you are on to something there. Please open a ticket 
and I will look later on. There's another change near that area that 
needs to be made with POST, I will look at both at the same time.

> But then I'm not totally sure how to interpret
> http://tools.ietf.org/html/rfc2616#section-10.2.2 which states
>
>     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.
>
>
> Because currently it is totally possible to not have a location header set (just as no body) for the response. In my opinion the current code behaves good enough and it's up to the service to ensure the requirements as stated by the RFC. Should cowboy enforce a header field? Should it try to figure that out on its own?

201 does not require a location header if the resource is created at the 
path indicated by the request. Specifying a different URI is a rare 
occurrence with PUT, it should only occur if you create the resource on 
a different domain name (think a CDN pushing the file to a subdomain).

And as Camille stated, forget RFC 2616, the various RFCs from httpbis is 
where it's at now.

-- 
Loïc Hoguin
http://ninenines.eu


More information about the Extend mailing list