Skip to main content
405

Method Not Allowed

Active
RFC 9110 §15.5.6Since 1997REST APIs, web servers, CORS issues

HTTP 405 Method Not Allowed indicates the request method is recognized by the server but is not supported by the target resource. Defined in RFC 9110 §15.5.6. The response MUST include an Allow header listing the methods the resource actually supports.

Description

The 405 Method Not Allowed status code indicates that the method received in the request-line is known by the origin server but not supported by the target resource. The origin server MUST generate an Allow header field in a 405 response containing a list of the target resource's currently supported methods.

This is distinct from 501 Not Implemented — 405 means the server knows the method but this particular resource doesn't accept it, while 501 means the server doesn't recognize or support the method at all.

A common source of confusion: CORS preflight requests use the OPTIONS method. If your server returns 405 for OPTIONS, the browser's preflight fails and the actual request never fires. This often looks like a CORS error to the developer when the root cause is a missing OPTIONS handler.

Another subtle case: some web frameworks auto-generate 405 responses with the correct Allow header when you define routes for specific methods. Others return 404 instead, which is technically incorrect if the resource exists but doesn't accept the given method.

Examples

PUT request to a read-only resource
http
PUT /api/system/status HTTP/1.1
Host: api.example.com
Content-Type: application/json
Authorization: Bearer token123

{"status": "maintenance"}
405 response with Allow header
http
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Content-Length: 127 
{"error": "method_not_allowed", "message": "PUT is not supported for /api/system/status. Supported methods: GET, HEAD, OPTIONS."}
DELETE on a collection endpoint
http
DELETE /api/users HTTP/1.1
Host: api.example.com
Authorization: Bearer admin-token
405 response (cannot delete entire collection)
http
HTTP/1.1 405 Method Not Allowed
Allow: GET, POST, HEAD
Content-Type: application/json

{"error": "method_not_allowed", "message": "Cannot DELETE the entire /users collection. DELETE individual users at /api/users/{id}."}

Edge Cases

  • The Allow header is REQUIRED in a 405 response — omitting it violates the spec and leaves clients guessing which methods work.
  • 405 is about the RESOURCE, not the server. The same server can return 405 on /read-only and accept PUT on /writable.
  • CORS preflight uses OPTIONS. If OPTIONS returns 405, the browser treats it as a CORS failure. Always handle OPTIONS on endpoints that need cross-origin access.
  • Some frameworks return 404 when a resource exists but doesn't support the method. This is incorrect — 405 with Allow is the right response.
  • HEAD should almost never return 405 — RFC 9110 requires that any resource supporting GET must also support HEAD.
  • The Allow header values should match the actual route definitions. If you add a new method to an endpoint, update the Allow list.

When You'll See This

  • Sending PUT or DELETE to a read-only resource (like a public API status page)
  • POST to an endpoint that only accepts GET (e.g., a search endpoint that uses query params)
  • Attempting to PATCH a resource that only supports full replacement via PUT
  • Trying to DELETE an entire collection when only individual items are deletable
  • CORS preflight failure because OPTIONS isn't handled (appears as 405 to the server, CORS error to the browser)

Implementation References

LanguageConstant
Gohttp.StatusMethodNotAllowed
Rusthttp::StatusCode::METHOD_NOT_ALLOWED
Pythonhttp.HTTPStatus.METHOD_NOT_ALLOWED
Node.jshttp.STATUS_CODES[405]
.NETHttpStatusCode.MethodNotAllowed
JavaHttpURLConnection.HTTP_BAD_METHOD
PHPResponse::HTTP_METHOD_NOT_ALLOWED (Symfony)
Ruby:method_not_allowed (Rack)

History

Introduced in HTTP/1.1 (RFC 2068, 1997). Became essential with RESTful API design where each resource explicitly declares which HTTP methods it supports. Before REST, most web servers only used GET and POST, making 405 rare. Modern API frameworks auto-generate 405 responses from route definitions — Express, FastAPI, Spring, and Rails all handle this differently.

Related Status Codes

Related Headers

FAQ

What does the Allow header contain in a 405 response?

A comma-separated list of HTTP methods the resource currently supports. For example: Allow: GET, POST, HEAD. This header is mandatory in 405 responses per RFC 9110.

What is the difference between 405 and 501?

405 means the server recognizes the method but this specific resource doesn't support it (e.g., PUT on a read-only endpoint). 501 means the server doesn't implement the method at all (e.g., PATCH not supported by the entire server).

Why does my CORS request show 405?

Browsers send an OPTIONS preflight request before cross-origin requests. If your server returns 405 for OPTIONS (because you haven't added an OPTIONS handler), the preflight fails. Add an OPTIONS handler that returns 200 with Access-Control-Allow-Methods.