201 Created
Usage
The 201 Created status code is returned when a request creates one or more new resources. This commonly follows a POST or PUT request. The server includes a Location header pointing to the newly created resource. When the Location header is absent, the created resource lives at the path specified in the original request.
The spec allows a body in a 201 response. REST convention is to return the created resource representation, including server-assigned fields such as id, timestamps, and URIs. This avoids a follow-up GET request to retrieve the new resource. The Location header points to the new resource URI.
Example
The client uploads XML data to the server, specifying /incoming/xml as the destination path. The server responds confirming the data was accepted and a file named article_1.xml was created.
Request
POST /incoming/xml HTTP/1.1
Host: example.com
Content-Type: application/xml
Content-Length: 105
<?xml version="1.0"?>
<article>
<title>Test XML article</title>
<author>Anonymous</author>
</article>
Response
HTTP/1.1 201 Created
Location: /incoming/xml/article_1.xml
Content-Type: application/json
Content-Length: 18
{"success":"true"}
Code references
.NET
HttpStatusCode.Created
Rust
http::StatusCode::CREATED
Rails
:created
Go
http.StatusCreated
Symfony
Response::HTTP_CREATED
Python3.5+
http.HTTPStatus.CREATED
Java
java.net.HttpURLConnection.HTTP_CREATED
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_CREATED
Angular
@angular/common/http/HttpStatusCode.Created