Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I handle unsupported verbs on a resource?

Tags:

rest

http

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?

like image 378
Peter Horne Avatar asked Dec 09 '22 15:12

Peter Horne


1 Answers

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]

like image 73
thomasrutter Avatar answered Dec 13 '22 23:12

thomasrutter