201 Created - HTTP | MDN
Summary
The 201 Created HTTP status code signals successful resource creation after a POST or PUT request. The response includes the new resource, often with a Location header pointing to its URL. An example shows a POST to http://example.com/users, returning 201 with a message, user object, and Location header. The code also carries a Location header for client navigation. This article, from MDN, outlines the code's usage and includes a concrete example.
Status
http
201 Created
Examples
Receiving a response indicating user creation
Let's assume there's a REST API for managing users with an endpoint at http://example.com/users. In this example, we send a POST request with the following body to create a user:
http
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
{
"firstName": "Brian",
"lastName": "Smith",
"email": "brian.smith@example.com"
}
After successful user creation, the 201 Created response will look like this:
http
HTTP/1.1 201 Created
Content-Type: application/json
Location: http://example.com/users/123
{
"message": "New user created",
"user": {
"id": 123,
"firstName": "Brian",
"lastName": "Smith",
"email": "brian.smith@example.com"
}
}
Specifications
| Specification |
|---|
| HTTP Semantics # status.201 |
See also
Help improve MDN
Was this page helpful to you?Yes No
This page was last modified on by MDN contributors.
Report this article
Tell us what's wrong. Every field is optional.