Skip to content

Commit 0f85678

Browse files
authored
Standardize and clarify success (2xx) responses (json-api#1638)
1 parent 25c6982 commit 0f85678

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed

_format/1.1/index.md

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,17 +1531,15 @@ to create a resource with a client-generated ID.
15311531

15321532
##### <a href="#crud-creating-responses-201" id="crud-creating-responses-201" class="headerlink"></a> 201 Created
15331533

1534-
If a `POST` request did not include a [Client-Generated
1535-
ID](#crud-creating-client-ids) and the requested resource has been created
1536-
successfully, the server **MUST** return a `201 Created` status code.
1534+
If the requested resource has been created successfully and the server changes
1535+
the resource in any way (for example, by assigning an `id`), the server **MUST**
1536+
return a `201 Created` response and a document that contains the resource as
1537+
primary data.
15371538

15381539
The response **SHOULD** include a `Location` header identifying the location
15391540
of the newly created resource, in order to comply with [RFC
15401541
7231](http://tools.ietf.org/html/rfc7231#section-6.3.2).
15411542

1542-
The response **MUST** also include a document that contains the primary
1543-
resource created.
1544-
15451543
If the [resource object][resource objects] returned by the response contains a `self` key in its
15461544
`links` member and a `Location` header is provided, the value of the `self`
15471545
member **MUST** match the value of the `Location` header.
@@ -1566,6 +1564,15 @@ Content-Type: application/vnd.api+json
15661564
}
15671565
```
15681566

1567+
A server **MAY** return a `201 Created` response with a document that contains
1568+
no primary data if the requested resource has been created successfully and the
1569+
server does not change the resource in any way (for example, by assigning an
1570+
`id` or `createdAt` attribute). Other top-level members, such as [meta], could
1571+
be included in the response document.
1572+
1573+
> Note: Only servers that accept [Client-Generated
1574+
IDs](#crud-creating-client-ids) can avoid assigning an `id` to a new resource.
1575+
15691576
##### <a href="#crud-creating-responses-202" id="crud-creating-responses-202" class="headerlink"></a> 202 Accepted
15701577

15711578
If a request to create a resource has been accepted for processing, but the
@@ -1574,15 +1581,11 @@ server **MUST** return a `202 Accepted` status code.
15741581

15751582
##### <a href="#crud-creating-responses-204" id="crud-creating-responses-204" class="headerlink"></a> 204 No Content
15761583

1577-
If a `POST` request *did* include a [Client-Generated
1578-
ID](#crud-creating-client-ids) and the requested resource has been created
1579-
successfully, the server **MUST** return either a `201 Created` status code
1580-
and response document (as described above) or a `204 No Content` status code
1581-
with no response document.
1582-
1583-
> Note: If a `204` response is received the client should consider the resource
1584-
object sent in the request to be accepted by the server, as if the server
1585-
had returned it back in a `201` response.
1584+
If the requested resource has been created successfully and the server does not
1585+
change the resource in any way (for example, by assigning an `id` or `createdAt`
1586+
attribute), the server **MUST** return either a `201 Created` status code and
1587+
response document (as described above) or a `204 No Content` status code with no
1588+
response document.
15861589

15871590
##### <a href="#crud-creating-responses-403" id="crud-creating-responses-403" class="headerlink"></a> 403 Forbidden
15881591

@@ -1745,31 +1748,30 @@ does not want to allow deletion of records the client has not seen.
17451748

17461749
#### <a href="#crud-updating-responses" id="crud-updating-responses" class="headerlink"></a> Responses
17471750

1751+
##### <a href="#crud-updating-responses-200" id="crud-updating-responses-200" class="headerlink"></a> 200 OK
1752+
1753+
If a server accepts an update but also changes the targeted resource(s) in ways
1754+
other than those specified by the request (for example, updating the
1755+
`updatedAt` attribute or a computed `sha`), it **MUST** return a `200 OK`
1756+
response and a document that contains the updated resource(s) as primary data.
1757+
1758+
A server **MAY** return a `200 OK` response with a document that contains no
1759+
primary data if an update is successful and the server does not change the
1760+
targeted resource(s) in ways other than those specified by the request. Other
1761+
top-level members, such as [meta], could be included in the response document.
1762+
17481763
##### <a href="#crud-updating-responses-202" id="crud-updating-responses-202" class="headerlink"></a> 202 Accepted
17491764

17501765
If an update request has been accepted for processing, but the processing
17511766
has not been completed by the time the server responds, the server **MUST**
17521767
return a `202 Accepted` status code.
17531768

1754-
##### <a href="#crud-updating-responses-200" id="crud-updating-responses-200" class="headerlink"></a> 200 OK
1755-
1756-
If a server accepts an update but also changes the resource(s) in ways other
1757-
than those specified by the request (for example, updating the `updated-at`
1758-
attribute or a computed `sha`), it **MUST** return a `200 OK` response. The
1759-
response document **MUST** include a representation of the updated
1760-
resource(s) as if a `GET` request was made to the request URL.
1761-
1762-
A server **MUST** return a `200 OK` status code if an update is successful,
1763-
the client's current fields remain up to date, and the server responds only
1764-
with top-level [meta] data. In this case the server **MUST NOT** include a
1765-
representation of the updated resource(s).
1766-
17671769
##### <a href="#crud-updating-responses-204" id="crud-updating-responses-204" class="headerlink"></a> 204 No Content
17681770

1769-
If an update is successful and the server doesn't update any fields besides
1770-
those provided, the server **MUST** return either a `200 OK` status code and
1771-
response document (as described above) or a `204 No Content` status code with no
1772-
response document.
1771+
If an update is successful and the server doesn't change the targeted
1772+
resource(s) in ways other than those specified by the request, the server
1773+
**MUST** return either a `200 OK` status code and response document (as
1774+
described above) or a `204 No Content` status code with no response document.
17731775

17741776
##### <a href="#crud-updating-relationship-responses-403" id="crud-updating-relationship-responses-403" class="headerlink"></a> 403 Forbidden
17751777

@@ -1968,6 +1970,18 @@ server, and we are defining its semantics for JSON:API.
19681970

19691971
#### <a href="#crud-updating-relationship-responses" id="crud-updating-relationship-responses" class="headerlink"></a> Responses
19701972

1973+
##### <a href="#crud-updating-relationship-responses-200" id="crud-updating-relationship-responses-200" class="headerlink"></a> 200 OK
1974+
1975+
If a server accepts an update but also changes the targeted relationship in
1976+
other ways than those specified by the request, it **MUST** return a `200 OK`
1977+
response and a document that includes the updated relationship data as its
1978+
primary data.
1979+
1980+
A server **MAY** return a `200 OK` response with a document that contains no
1981+
primary data if an update is successful and the server does not change the
1982+
targeted relationship in ways other than those specified by the request. Other
1983+
top-level members, such as [meta], could be included in the response document.
1984+
19711985
##### <a href="#crud-updating-relationship-responses-202" id="crud-updating-relationship-responses-202" class="headerlink"></a> 202 Accepted
19721986

19731987
If a relationship update request has been accepted for processing, but the
@@ -1976,28 +1990,17 @@ server **MUST** return a `202 Accepted` status code.
19761990

19771991
##### <a href="#crud-updating-relationship-responses-204" id="crud-updating-relationship-responses-204" class="headerlink"></a> 204 No Content
19781992

1979-
A server **MUST** return a `204 No Content` status code if an update is
1980-
successful and the representation of the resource in the request matches the
1981-
result.
1993+
If an update is successful and the server doesn't change the targeted
1994+
relationship in ways other than those specified by the request, the server
1995+
**MUST** return either a `200 OK` status code and response document (as
1996+
described above) or a `204 No Content` status code with no response document.
19821997

19831998
> Note: This is the appropriate response to a `POST` request sent to a URL
19841999
from a to-many [relationship link][relationships] when that relationship already
19852000
exists. It is also the appropriate response to a `DELETE` request sent to a URL
19862001
from a to-many [relationship link][relationships] when that relationship does
19872002
not exist.
19882003

1989-
##### <a href="#crud-updating-relationship-responses-200" id="crud-updating-relationship-responses-200" class="headerlink"></a> 200 OK
1990-
1991-
If a server accepts an update but also changes the targeted relationship(s)
1992-
in other ways than those specified by the request, it **MUST** return a `200
1993-
OK` response. The response document **MUST** include a representation of the
1994-
updated relationship(s).
1995-
1996-
A server **MUST** return a `200 OK` status code if an update is successful,
1997-
the client's current data remain up to date, and the server responds
1998-
only with top-level [meta] data. In this case the server **MUST NOT**
1999-
include a representation of the updated relationship(s).
2000-
20012004
##### <a href="#crud-updating-relationship-responses-403" id="crud-updating-relationship-responses-403" class="headerlink"></a> 403 Forbidden
20022005

20032006
A server **MUST** return `403 Forbidden` in response to an unsupported request
@@ -2025,6 +2028,12 @@ Accept: application/vnd.api+json
20252028

20262029
#### <a href="#crud-deleting-responses" id="crud-deleting-responses" class="headerlink"></a> Responses
20272030

2031+
##### <a href="#crud-deleting-responses-200" id="crud-deleting-responses-200" class="headerlink"></a> 200 OK
2032+
2033+
A server **MAY** return a `200 OK` response with a document that contains no
2034+
primary data if a deletion request is successful. Other top-level members, such
2035+
as [meta], could be included in the response document.
2036+
20282037
##### <a href="#crud-deleting-responses-202" id="crud-deleting-responses-202" class="headerlink"></a> 202 Accepted
20292038

20302039
If a deletion request has been accepted for processing, but the processing has
@@ -2033,13 +2042,9 @@ return a `202 Accepted` status code.
20332042

20342043
##### <a href="#crud-deleting-responses-204" id="crud-deleting-responses-204" class="headerlink"></a> 204 No Content
20352044

2036-
A server **MUST** return a `204 No Content` status code if a deletion
2037-
request is successful and no content is returned.
2038-
2039-
##### <a href="#crud-deleting-responses-200" id="crud-deleting-responses-200" class="headerlink"></a> 200 OK
2040-
2041-
A server **MUST** return a `200 OK` status code if a deletion request is
2042-
successful and the server responds with only top-level [meta] data.
2045+
If a deletion request is successful, the server **MUST** return either a `200
2046+
OK` status code and response document (as described above) or a `204 No Content`
2047+
status code with no response document.
20432048

20442049
##### <a href="#crud-deleting-responses-404" id="crud-deleting-responses-404" class="headerlink"></a> 404 NOT FOUND
20452050

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy