What is HTTP Response Status Code 405 Method Not Allowed?
HTTP response status code 405 Method Not Allowed indicates that the server understands the request method, but the method is not allowed for the requested resource. It means that the client should use a different method for accessing the resource.
The server’s response will include the Allow
header, listing the methods that are supported for the resource.
This status code is often encountered when a client attempts to perform a disallowed operation, such as sending a DELETE
request to a resource that only supports GET
and POST
.
It helps ensure that clients adhere to the appropriate methods when interacting with APIs or resources, preventing unsupported operations that could cause errors or data integrity issues.
Example 1: Disallowed DELETE Request
# Client sends a DELETE request for a resource that does not support deletion. DELETE /users/12345 HTTP/1.1 Host: www.example.com # Server Response HTTP/1.1 405 Method Not Allowed Date: Wed, 09 Oct 2024 14:30:00 GMT Server: Apache/2.4.41 (Ubuntu) Allow: GET, POST # The server informs the client that the DELETE method is not allowed.
Example 2: Unsupported PUT Request
# Client sends a PUT request to a resource that only supports GET. PUT /blog/posts HTTP/1.1 Host: www.example.com # Server Response HTTP/1.1 405 Method Not Allowed Date: Wed, 09 Oct 2024 14:32:00 GMT Server: Nginx/1.18.0 Allow: GET # The server informs the client that only GET is supported for this resource.
Summary
The HTTP 405 Method Not Allowed status code is used when the client tries to use a method that is not permitted for the resource. It helps maintain proper API usage by specifying allowed methods, ensuring clients interact correctly with the resource.