HTTP Status 405 - Method Not Allowed

Der HTTP-Status-Code 405 Method Not Allowed signalisiert, dass die verwendete HTTP-Methode für die angefragte Resource nicht unterstützt wird. Response muss Allow Header mit Liste erlaubter Methoden enthalten. Resource existiert, aber Methode ist nicht erlaubt.

Typ

Response-Status-Code

Syntax

Der Status Code wird mit Allow Header zurückgegeben.

http
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS

Direktiven

Der 405 Method Not Allowed Status Code wird für unerlaubte HTTP-Methoden verwendet.

Method Not Supported
Resource existiert unter dieser URI, aber die verwendete HTTP-Methode wird nicht unterstützt. Unterscheidet sich von 404 (Resource existiert nicht).
Allow Header Required
Response muss Allow Header enthalten, der alle unterstützten Methoden für diese Resource auflistet (z.B. GET, POST, PUT, DELETE).
Read-Only Resources
Häufig für Read-Only-APIs, wo nur GET/HEAD erlaubt sind, aber Client POST/PUT/DELETE versucht. Oder für immutable Resources ohne DELETE-Support.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für Status 405.

Beispiel 1 DELETE Not Allowed

http
DELETE /api/system/config HTTP/1.1
Host: api.example.com

HTTP/1.1 405 Method Not Allowed
Allow: GET, PUT
Content-Type: application/json

{
  "error": "method_not_allowed",
  "message": "DELETE not supported for system config",
  "allowed_methods": ["GET", "PUT"]
}

Beispiel 2 POST on Read-Only Resource

http
POST /api/statistics HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"metric": "value"}

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS
Content-Type: application/json

{
  "error": "read_only_resource",
  "message": "Statistics endpoint is read-only",
  "allowed_methods": ["GET", "HEAD", "OPTIONS"]
}

Beispiel 3 PATCH Not Implemented

http
PATCH /api/orders/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json

[{"op": "replace", "path": "/status", "value": "shipped"}]

HTTP/1.1 405 Method Not Allowed
Allow: GET, PUT, DELETE
Content-Type: application/json

{
  "error": "method_not_allowed",
  "message": "PATCH not supported, use PUT for full updates",
  "allowed_methods": ["GET", "PUT", "DELETE"]
}

Method Not Allowed Flow

405 Method Not Allowed Response bei unerlaubter HTTP Method

Vorteile für die Systemarchitektur

  • Clear API Contracts: Allow Header dokumentiert explizit, welche Methods Resource unterstützt. Client kann dynamisch ermitteln, welche Operations möglich sind (HATEOAS).
  • Security Enforcement: Verhindert ungewollte Mutations auf Read-Only-Resources oder kritischen System-Endpoints. Gateway kann Method-Restrictions durchsetzen.
  • API Evolution: Ermöglicht schrittweises Hinzufügen von Methods zu Resources. Legacy-Clients erhalten 405 für neue Methods mit klarer Indication verfügbarer Alternativen.

Spezifikation

RFC 9110, Section 15.5.6 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-405-method-not-allowed

Weitere Spezifikationen

Allow Header, OPTIONS Method