REST status codes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

REST status codes

pledbrook
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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Graeme Rocher-2
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

On Thu, Feb 13, 2014 at 3:52 PM, Peter Ledbrook <[hidden email]> wrote:

> 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
Grails Project Lead
SpringSource

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

pledbrook
> 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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

pledbrook
>> 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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Graeme Rocher-2
Well I'm open to status code suggestions

Cheers

On Wed, Feb 19, 2014 at 9:16 AM, Peter Ledbrook <[hidden email]> wrote:

>>> 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
Grails Project Lead
SpringSource

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Graeme Rocher-2
In reply to this post by pledbrook
On this subject, how about a 501 "Not Implemented"?

That is the only code I can find that seems appropriate

Cheers

On Wed, Feb 19, 2014 at 9:09 AM, Peter Ledbrook <[hidden email]> wrote:

>> 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
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Graeme Rocher-2
In reply to this post by pledbrook
On Wed, Feb 19, 2014 at 9:16 AM, Peter Ledbrook <[hidden email]> wrote:

>>> 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

>
> 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
Grails Project Lead
SpringSource

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

pledbrook
>> 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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

David Estes
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

On March 3, 2014 at 1:06:01 PM, Peter Ledbrook ([hidden email]) wrote:

>> 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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Robert Fletcher-2
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.


On Mon, Mar 3, 2014 at 6:23 PM, David Estes <[hidden email]> wrote:

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

On March 3, 2014 at 1:06:01 PM, Peter Ledbrook ([hidden email]) wrote:

>> 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



Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

rlovtangen

On 03 Mar 2014, at 20:43, Robert Fletcher <[hidden email]> wrote:

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.

422 is a WebDAV extension (http://tools.ietf.org/html/rfc4918#section-11.2), but it was probably Rails that made it popular.



On Mon, Mar 3, 2014 at 6:23 PM, David Estes <[hidden email]> wrote:

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

On March 3, 2014 at 1:06:01 PM, Peter Ledbrook ([hidden email]) wrote:

>> 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




Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

cdeszaq
In reply to this post by Robert Fletcher-2
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.



On Mon, Mar 3, 2014 at 1:43 PM, Robert Fletcher <[hidden email]> wrote:
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.


On Mon, Mar 3, 2014 at 6:23 PM, David Estes <[hidden email]> wrote:

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

On March 3, 2014 at 1:06:01 PM, Peter Ledbrook ([hidden email]) wrote:

>> 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




Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

Robert Fletcher-2
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


Reply | Threaded
Open this post in threaded view
|

Re: REST status codes

sskubikpeplaski
In reply to this post by cdeszaq
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.