-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
65 lines (48 loc) · 1.67 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: 201 Created
slug: Web/HTTP/Status/201
page-type: http-status-code
spec-urls: https://www.rfc-editor.org/rfc/rfc9110#status.201
---
{{HTTPSidebar}}
The HTTP **`201 Created`** [successful response](/en-US/docs/Web/HTTP/Status#successful_responses) status code indicates that the HTTP request has led to the creation of a resource.
This status code is commonly sent as the result of a {{HTTPMethod("POST")}} request.
The new resource, or a description and link to the new resource, is created before the response is returned.
The newly-created items are returned in the body of the message, located at either the **URL of the initial request** or the URL in the value of the {{HTTPHeader("Location")}} header in the response.
## 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
{{Specifications}}
## See also
- [HTTP request methods](/en-US/docs/Web/HTTP/Methods)
- [HTTP response status codes](/en-US/docs/Web/HTTP/Status)