I am building a RESTful API. When the client uses an unsupported method such as POST on a resource that does not supports it, I am returning a 405
with the Allow
header which lists the allowed methods:
Status Code: 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Connection: keep-alive
Date: Mon, 08 Apr 2013 00:19:26 GMT
Transfer-Encoding: chunked
Is it allowed to have a body (to provide an error message) for 405
responses?
From the w3c's site, it is not apparent whether a body is allowed for 405
responses.
The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn't support this method. The server must generate an Allow header field in a 405 status code response.
A 405 Method Not Allowed Error is an HTTP response status code that indicates a web browser has requested access to one of your web pages and your web server received and recognized its HTTP method.
HTTP response status code 405 means Method Not Allowed . This status code states that HTTP method was received and recognized by the server, but the server has rejected that particular method for the requested resource. Try to access an existing resource without the proper permission.
The HTTP/1.1 protocol spec states in the "message length" section:
Any response message which "MUST NOT" include a message-body (the 1xx, 204, and 304 responses and any response to a HEAD request) is always terminated by the first empty line after the header fields, regardless of the entity-header fields present in the message.
A message body is optional for all 4xx-5xx codes as long as the HTTP method is not HEAD
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With