Qaynaq LABS · TOOLS

HTTP · 4xx Client Error

405 Method Not Allowed

The HTTP method used is not supported for the requested resource.

When you see this status

  • Client sends a request with an unsupported HTTP method (e.g., POST to a read-only endpoint)
  • Server explicitly rejects a method via Allow header restrictions
  • API versioning conflicts prevent method usage

Common causes

  • Incorrect HTTP method in client request (e.g., GET vs POST)
  • Server-side route misconfiguration
  • Missing or misconfigured CORS preflight handling
  • API endpoint does not support the requested method

How to debug it

  1. Verify the HTTP method used in the request
  2. Check server route definitions for method support
  3. Inspect the Allow header in the response
  4. Test with curl: `curl -X <method> <url>`
  5. Review server logs for route resolution failures

Return this code in your framework

Express (Node.js)
app.all('/resource', (req, res) => res.status(405).set('Allow', 'GET').send());
FastAPI (Python)
from fastapi import FastAPI, status
app = FastAPI()
@app.post('/resource')
async def handle_post(): return JSONResponse(status_code=405, headers={'Allow': 'GET'})
NestJS
import { Controller, Post, HttpCode } from '@nestjs/common';
@Controller('resource')
export class ResourceController {
  @Post() @HttpCode(405) handlePost() { return; }
}
Go (net/http)
http.HandleFunc("/resource", func(w http.ResponseWriter, r *http.Request) {
  if r.Method != "GET" {
    w.Header().Set("Allow", "GET")
    http.Error(w, "Method Not Allowed", 405)
  }
})

About HTTP 405

HTTP status code 405 Method Not Allowed is part of the 4xx Client Error family. The HTTP method used is not supported for the requested resource. Understanding it is essential for backend engineers, API designers, and anyone debugging integrations between services.

The Qaynaq Labs HTTP Status Code Explainer covers all standard codes with practical guidance: what triggers them, how to debug them in production, and exactly how to return them from common frameworks. Each code page is hand-curated and verified.

Frequently asked

Why does the server return an Allow header with 405?

The Allow header lists supported methods for the resource, aiding clients in retrying with valid methods.

Can 405 be used for OPTIONS requests?

Yes, OPTIONS requests may return 405 if the method is unsupported, but typically 200 or 204 is expected.

How to handle 405 in frontend applications?

Catch the error, inspect the Allow header, and prompt the user to retry with a supported method.