Discussion:
REST status codes
Peter Ledbrook
2014-02-13 14:52:50 UTC
Permalink
Hi,

I've been delving into some of the code behind the REST support and
noticed a couple of status codes that don't seem quite right to me.
The first is the use of 404 for a read-only resource:

https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy#L194

Surely that should be a 405 as the resource exists but doesn't support
POST, PUT or DELETE.

The other questionable status code is 415 when an appropriate renderer
can't be found for a particular resource:

https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy#L162

According to the spec, 415 (Unsupported Media Type) only applies if
the server can't deal with the *request* content type. I think 406
(Not Acceptable) is more appropriate, although even that's not ideal.

Thoughts?

Peter
--
Peter Ledbrook
t: @pledbrook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Graeme Rocher
2014-02-14 08:31:54 UTC
Permalink
On the former, agreed this seems worthy of a JIRA

On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.

Cheers
Post by Peter Ledbrook
Hi,
I've been delving into some of the code behind the REST support and
noticed a couple of status codes that don't seem quite right to me.
https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy#L194
Surely that should be a 405 as the resource exists but doesn't support
POST, PUT or DELETE.
The other questionable status code is 415 when an appropriate renderer
https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy#L162
According to the spec, 415 (Unsupported Media Type) only applies if
the server can't deal with the *request* content type. I think 406
(Not Acceptable) is more appropriate, although even that's not ideal.
Thoughts?
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Peter Ledbrook
2014-02-19 08:09:25 UTC
Permalink
Post by Graeme Rocher
On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.
Why would it be a programmer error if the user requests text/csv but
the application doesn't support it? Or is that what the mime types map
in Config.groovy is for? Should applications remove the mime types
that they don't handle?

Peter
--
Peter Ledbrook
t: @pledbrook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Peter Ledbrook
2014-02-19 08:16:38 UTC
Permalink
Post by Peter Ledbrook
Post by Graeme Rocher
On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.
Why would it be a programmer error if the user requests text/csv but
the application doesn't support it? Or is that what the mime types map
in Config.groovy is for? Should applications remove the mime types
that they don't handle?
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.

If there is some agreement on what the behaviour should be for these
scenarios, I'll raise an issue.

Peter
--
Peter Ledbrook
t: @pledbrook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Graeme Rocher
2014-02-19 09:25:10 UTC
Permalink
Well I'm open to status code suggestions

Cheers
Post by Peter Ledbrook
Post by Peter Ledbrook
Post by Graeme Rocher
On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.
Why would it be a programmer error if the user requests text/csv but
the application doesn't support it? Or is that what the mime types map
in Config.groovy is for? Should applications remove the mime types
that they don't handle?
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If there is some agreement on what the behaviour should be for these
scenarios, I'll raise an issue.
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Graeme Rocher
2014-03-03 10:19:25 UTC
Permalink
Post by Peter Ledbrook
Post by Peter Ledbrook
Post by Graeme Rocher
On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.
Why would it be a programmer error if the user requests text/csv but
the application doesn't support it? Or is that what the mime types map
in Config.groovy is for? Should applications remove the mime types
that they don't handle?
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"

Cheers
Post by Peter Ledbrook
If there is some agreement on what the behaviour should be for these
scenarios, I'll raise an issue.
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Peter Ledbrook
2014-03-03 18:05:55 UTC
Permalink
Post by Graeme Rocher
Post by Peter Ledbrook
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"
415 Unsupported Media Type. If the content type of the request is not
understood by the server, 415 seems best.

Cheers,

Peter
--
Peter Ledbrook
t: @pledbrook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
David Estes
2014-03-03 18:23:01 UTC
Permalink
406 definitely sounds appropriate here. General rule 400s mean I (the visitor) screwed up, 500 means the server screwed up. So

415 (Unsupported Media Type) has to do with if the request.body contains a format (typically in a POST or PUT request) that the server is unable to interpret.

where as a 406 - Not Acceptable is based on request headers and should be sent when the server is unable to return a response in the requested format.

-- 
David Estes
Sent with Airmail
Post by Graeme Rocher
Post by Peter Ledbrook
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"
415 Unsupported Media Type. If the content type of the request is not
understood by the server, 415 seems best.

Cheers,

Peter

--
Peter Ledbrook
t: @pledbrook

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Robert Fletcher
2014-03-03 19:43:32 UTC
Permalink
I agree with David's summation here. 406 seems to me the most appropriate. From Wikpedia: 
 The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
Also 422 is specifically designed for validation errors in REST interfaces. IIRC it came from Rails originally. It means the request could be parsed but not processed as it contained semantic errors.
406 definitely sounds appropriate here. General rule 400s mean I (the visitor) screwed up, 500 means the server screwed up. So
415 (Unsupported Media Type) has to do with if the request.body contains a format (typically in a POST or PUT request) that the server is unable to interpret.
where as a 406 - Not Acceptable is based on request headers and should be sent when the server is unable to return a response in the requested format.
-- 
David Estes
Sent with Airmail
Post by Graeme Rocher
Post by Peter Ledbrook
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"
415 Unsupported Media Type. If the content type of the request is not
understood by the server, 415 seems best.
Cheers,
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Ronny Løvtangen
2014-03-03 19:58:59 UTC
Permalink
Post by Robert Fletcher
The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
Also 422 is specifically designed for validation errors in REST interfaces. IIRC it came from Rails originally. It means the request could be parsed but not processed as it contained semantic errors.
422 is a WebDAV extension (http://tools.ietf.org/html/rfc4918#section-11.2), but it was probably Rails that made it popular.
Post by Robert Fletcher
406 definitely sounds appropriate here. General rule 400s mean I (the visitor) screwed up, 500 means the server screwed up. So
415 (Unsupported Media Type) has to do with if the request.body contains a format (typically in a POST or PUT request) that the server is unable to interpret.
where as a 406 - Not Acceptable is based on request headers and should be sent when the server is unable to return a response in the requested format.
--
David Estes
Sent with Airmail
Post by Graeme Rocher
Post by Peter Ledbrook
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"
415 Unsupported Media Type. If the content type of the request is not
understood by the server, 415 seems best.
Cheers,
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Rick Jensen
2014-03-03 19:59:40 UTC
Permalink
I would agree with David. 406 is the best fit for "you asked for something
in a format in which I am not able to represent it". 406 == *response type*
requested is not available, 415 == *request type* specified is not
acceptable. (http://httpstatus.es/406 vs. http://httpstatus.es/415)

In the case of a 406, the server can still respond with it's "best effort"
representation, which could default to HTML or JSON or, really, anything
the server wishes. Since this should only happen if the server cannot
respond with any of the desired representation, the request has failed, so
anything that _does_ come back is only an attempt to try to give
_something_ useful.

And Rob is right in that 422 is targeted at a higher level than the HTTP
protocol (which deals with indicating content types sent / accepted). 422
is for api-specific issues along the lines of "I understood what you said,
but I don't like it (ie. You gave me a Foo, but I need a Bar)

501 is more targeted at the HTTP METHOD of the request (ie. GET, POST, PUT,
etc.) and would be an appropriate response if PATCH (for example) was the
request HTTP method, but was not supported (by the whole server, or for
just a single resource.
Post by Robert Fletcher
I agree with David's summation here. 406 seems to me the most appropriate.
The requested resource is only capable of generating content not
acceptable according to the Accept headers sent in the request.
Also 422 is specifically designed for validation errors in REST
interfaces. IIRC it came from Rails originally. It means the request could
be parsed but not processed as it contained semantic errors.
406 definitely sounds appropriate here. General rule 400s mean I (the
visitor) screwed up, 500 means the server screwed up. So
415 (Unsupported Media Type) has to do with if the request.body contains
a format (typically in a POST or PUT request) that the server is unable to
interpret.
where as a 406 - Not Acceptable is based on request headers and should be
sent when the server is unable to return a response in the requested format.
--
David Estes
Sent with Airmail
Post by Graeme Rocher
Post by Peter Ledbrook
Grails also doesn't reject requests with an unsupported content type.
I've tried submitting content of the form text/csv and just got a 422
back with some validation errors.
If not a 422 what would you expect to get? 422 seems appropriate here,
other option is just a 400 "Bad Request"
415 Unsupported Media Type. If the content type of the request is not
understood by the server, 415 seems best.
Cheers,
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Rob Fletcher
2014-03-04 09:29:23 UTC
Permalink
501 is a weird one. I’ve never encountered it in use & I can’t think of a situation where I wouldn’t rather use 405.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
sskubikpeplaski
2014-04-21 11:35:11 UTC
Permalink
I also agree with David. Has there been any decision made on this issue? I've
checked through Jira and was unable to find an issue logged there.




--
View this message in context: http://grails.1312388.n4.nabble.com/REST-status-codes-tp4654080p4656180.html
Sent from the Grails - dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Graeme Rocher
2014-03-03 10:18:24 UTC
Permalink
On this subject, how about a 501 "Not Implemented"?

That is the only code I can find that seems appropriate

Cheers
Post by Peter Ledbrook
Post by Graeme Rocher
On the latter, good point... maybe it should be a 500 since it is an
application / programmer error if you haven't supplied a renderer.
Why would it be a programmer error if the user requests text/csv but
the application doesn't support it? Or is that what the mime types map
in Config.groovy is for? Should applications remove the mime types
that they don't handle?
Peter
--
Peter Ledbrook
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Loading...