tool::http-status-detail
201 Created
The request has been fulfilled and a new resource has been created.
Statuscode
201
Name
Created
Kategorie
2xxDetaillierte Erklärung
HTTP 201 Created zeigt an, dass die Anfrage erfolgreich verarbeitet wurde und eine neue Ressource erstellt wurde. Es sollte anstelle von 200 OK verwendet werden, wenn eine POST-Anfrage einen neuen Benutzer, Beitrag, Auftrag oder eine andere Ressource erstellt. Die REST-API-Best-Practice empfiehlt, die URL der neu erstellten Ressource im Location-Header zurückzugeben.
Häufige Ursachen
- ▸Eine POST-Anfrage hat erfolgreich einen neuen Datenbankdatensatz erstellt
- ▸Ein Datei-Upload war erfolgreich und eine neue Dateiressource wurde angelegt
- ▸Benutzerregistrierung, Beitragserstellung, Bestellaufgabe oder andere Erstellungsoperationen
- ▸Eine PUT-Anfrage hat eine bisher nicht vorhandene Ressource neu erstellt
Lösungsansätze
- 1.201 ist eine normale Antwort — keine Korrektur erforderlich
- 2.Fügen Sie einen Location-Header mit der URL der neu erstellten Ressource hinzu
- 3.Empfehlenswert ist die Rückgabe der vollständigen Ressourcendaten im Antwortkörper
- 4.Verwenden Sie 200 OK für erfolgreiche Lesezugriffe, nicht für die Ressourcenerstellung
Zugehörige HTTP-Header
LocationContent-TypeETagAntwortbeispiel
HTTP/1.1 201 Created
Location: /api/users/42
Content-Type: application/json
{"id":42,"name":"Jane Doe","email":"jane@example.com"}Verwandte Statuscodes
200OKThe request has succeeded.→202AcceptedThe request has been accepted but not yet acted upon.→203Non-Authoritative InformationThe response is from a transforming proxy, not the origin server.→204No ContentThe server successfully processed the request but returns no content.→205Reset ContentThe server processed the request; the client should reset the document view.→
ad · 300×250
// related tools