405 Method Not Allowed

noun

say it: “FOR-oh-FYVE METH-ud not uh-LOWD” /ˈfɔr oʊ faɪv ˈmɛθəd nɑt əˈlaʊd/

An HTTP status code meaning the address exists but doesn't accept the method used, such as DELETE sent to a path that only answers GET.

What does 405 Method Not Allowed mean?

405 Method Not Allowed means the address exists but doesn't take that method, such as DELETE on a path that only answers GET. It differs from 404, which says nothing is at the address at all. The Allow header lists the methods that path does take.

from fastapi import FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

@app.get("/plots")
def list_plots():
    return [{"id": 7, "crop": "tomatoes"}]

response = TestClient(app).delete("/plots")
print(response.status_code, response.json())   # 405 {'detail': 'Method Not Allowed'}
print(response.headers["allow"])               # GET

In a sentence

  • “The test expects 405 Method Not Allowed, not 404, because /plots is there; it just doesn't take PUT.”
  • “Sending DELETE to /plots, which only lists plots, got Priya a 405 Method Not Allowed and an Allow header that said GET.”

Level: Apprentice · More REST API terms at this level

Updated