405 Method Not Allowed means: The resource exists but does not support the request method. The server must send an Allow header listing the methods it does support — e.g. a read-only endpoint answering GET/HEAD but rejecting POST. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 405 when posting to a read-only or get-only endpoint; using put where the api only implements patch (or vice versa); a framework route registered for some verbs but not the one used. On the client side, read the Allow header and switch to a supported method; check the API docs for the correct verb for this operation. On the server side, always include Allow with 405; register routes explicitly and return 405 (not 404) when the path exists but the verb does not.
When 405 happens
- POSTing to a read-only or GET-only endpoint
- Using PUT where the API only implements PATCH (or vice versa)
- A framework route registered for some verbs but not the one used
How to fix it
On the client
Read the Allow header and switch to a supported method; check the API docs for the correct verb for this operation.
On the server
Always include Allow with 405; register routes explicitly and return 405 (not 404) when the path exists but the verb does not.
Should you retry?
Not retryable as-is: change the request (credentials, payload, URL) first.
Debugging steps
When 405 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: posting to a read-only or get-only endpoint. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.
Notes & gotchas
The Allow header is mandatory on 405 and is the fastest path to a fix: it lists exactly which verbs the resource supports, so clients can self-correct without reading documentation.
Examples
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Content-Length: 95
{
"error": "method_not_allowed",
"message": "POSTing to a read-only or GET-only endpoint"
} curl -i -X POST https://api.example.com/v1/read-only-resource # inspect the Allow header const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 405) {
const problem = await res.json(); // read field-level details
// fix the request (credentials, payload, URL) — identical retries keep failing
throw new RequestError(problem);
} import requests
res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 405:
problem = res.json() # field-level error details
# correct the request before retrying — identical retries keep failing
raise RequestProblem(problem) Frequently asked questions
Why is the Allow header important?
It tells the client exactly which methods work, turning a dead end into an actionable fix; RFC 9110 requires it on 405 responses.
405 vs 501: both say 'method problem'?
405: this resource does not allow that method (others work). 501: the server does not implement the method at all, for any resource.
Are 4xx errors always the client's fault?
By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.
Should I retry 4xx responses automatically?
Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.
Try the JSON Validator
Check JSON syntax and locate errors by line and column.