tags:

views:

52

answers:

2

I am developing a RESTful framework and am deciding how to handle an unsupported verb being called against a resource. For example, someone trying to PUT to a read-only resource.

My initial thought was a 404 error, but the error is not that the resource cannot be found, it exists, just the user is trying to use the resource incorrectly. Is there a more appropriate error code? What is the most common way in which this situation is handled?

+9  A: 

Is it that you simply don't support a certain verb ie DELETE? In that case I'd use the following HTTP response code if someone uses a verb you don't support.

  • 405 Method Not Allowed

    A request was made of a resource using a request method not supported by that resource;[2] for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource. [source]

thomasrutter
I just read through the status codes, and that is the one I would of chosen +1
alex
Thanks! The 405 status code is just what I am looking for. I've updated the question to make it clearer that I am trying to handle situations in which a particular verb is not supported.
Pheter
A: 

I don't think you would receive a request to your app at all if the incorrect verb were used (but that probably depends on which specific technologies you're using on the server side).

To be more helpful to potentially confused client connection attempts I suppose you could create a stub endpoint/action for each commonly incorrect verb, method combinations and then send back a friendly "use {verbname} instead for this request" text response, but I'd personally just invest a bit of time in better developer documentation : )

You could also seamlessly redirect to the correct action in those cases...

Tahbaza