HTTP Status 400 - Bad Request

Der HTTP-Status-Code 400 Bad Request signalisiert, dass der Server den Request aufgrund eines Client-Fehlers nicht verarbeiten kann. Typische Ursachen sind Syntax-Fehler, ungültige Request-Parameter oder fehlerhafte JSON/XML-Struktur. Standard-Response für Validation-Failures in APIs.

Typ

Response-Status-Code

Syntax

Der Status Code wird zurückgegeben, wenn Request nicht verarbeitet werden kann.

http
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

Direktiven

Der 400 Bad Request Status Code wird für Client-seitige Request-Fehler verwendet.

Syntax Errors
Server konnte Request nicht parsen (malformed JSON/XML, invalid URL encoding, fehlende required Headers). Client muss Request-Format korrigieren.
Validation Failures
Request ist syntaktisch korrekt, aber semantisch ungültig (negative Zahlen wo positive erwartet, ungültige Enum-Werte, Constraint-Violations).
Generic Client Error
Wenn kein spezifischerer 4xx Status passt (401 für Auth, 404 für Not Found, 422 für Semantic Validation), ist 400 der fallback Client-Error.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für Status 400.

Beispiel 1 Malformed JSON Request

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

{"product_id": 42, "quantity":

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
  "type": "https://api.example.com/errors/malformed-json",
  "title": "Malformed JSON in request body",
  "detail": "Unexpected end of JSON input at line 1, column 35",
  "instance": "/api/orders"
}

Beispiel 2 Missing Required Parameter

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

{"username": "alice"}

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "validation_failed",
  "message": "Missing required field: email",
  "fields": {"email": "This field is required"}
}

Beispiel 3 Invalid Query Parameters

http
GET /api/products?page=invalid&limit=-10 HTTP/1.1
Host: api.example.com

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "invalid_parameters",
  "details": [
    {"param": "page", "message": "Must be a positive integer"},
    {"param": "limit", "message": "Must be between 1 and 100"}
  ]
}

Validation Error Response Flow

API Request Validation schlägt fehl und returned 400 Bad Request

Vorteile für die Systemarchitektur

  • Early Validation Feedback: Client erfährt sofort, dass Request ungültig ist. Verhindert unnötige Backend-Processing und Database-Zugriffe bei malformed Requests.
  • Clear Error Messages: Strukturierte Error-Responses (RFC 7807 Problem Details) helfen Client-Developers, Issues schnell zu identifizieren und zu fixen.
  • API Security: Validierung auf Gateway-Level blockiert malicious oder malformed Requests früh. Schützt Backend-Services vor Invalid-Input-Processing.

Spezifikation

RFC 9110, Section 15.5.1 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-400-bad-request

Weitere Spezifikationen

HTTP Status 422 - Unprocessable Entity, Content-Type Header, HTTP Status 200 - OK