8000 Attributes of relationships #415 #431: optional · json-api/json-api@7aca000 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7aca000

Browse files
committed
Attributes of relationships #415 #431: optional
1 parent 7315413 commit 7aca000

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

format/index.md

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ they represent "[relationship attributes]" and may contain any valid JSON value.
320320
Complex [relationship attributes] **MUST** abide by the same constraints as
321321
[complex resource attributes].
322322

323+
A linkage object **MAY** contain `"meta"` member: non-standard meta-information
324+
about linkage that can not be represented as a [relationship attribute].
325+
323326
> Note: Resource linkage in a compound document allows a client to link
324327
together all of the included resource objects without having to `GET` any
325328
relationship URLs.
@@ -817,49 +820,71 @@ GET /articles/1?include=author,comments,comments.author
817820

818821
### Sparse Fieldsets <a href="#fetching-sparse-fieldsets" id="fetching-sparse-fieldsets" class="headerlink"></a>
819822

820-
A client **MAY** request that an endpoint return only specific [fields] in the
821-
response on a per-type basis by including a `fields[TYPE]` parameter.
823+
A client **MAY** request that an endpoint return only specific [fields] and
824+
[relationship attributes] in the response on a per-type basis
825+
by including a `fields[TYPE]` parameter.
822826

823-
> Note: Only [fields] are affected; `type`, `id`, and (optionally) `self` are
824-
included as normal.
827+
> Note: Only [fields] and [relationship attributes] are affected;
828+
`type`, `id`, and (optionally) `self` are included as normal.
825829

826830
The value of the `fields` parameter **MUST** be a comma-separated (U+002C
827-
COMMA, ",") list that refers to the name(s) of the fields to be returned.
831+
COMMA, ",") list that refers to the name(s) of the [fields] and
832+
[relationship attributes] to be returned.
833+
[Relationship attributes] **MUST** be specified via dot-separated
834+
(U+002E FULL-STOP, ".") path which includes the following elements:
835+
`links`, name of the relationship, name of the [relationship attribute].
836+
837+
If a client requests a restricted set of [fields] and [relationship attributes],
838+
an endpoint **MUST NOT** include additional [fields] and
839+
[relationship attributes] in the response.
828840

829-
If a client requests a restricted set of [fields], an endpoint **MUST NOT**
830-
include additional [fields] in the response.
841+
An example for [fields]:
831842

832843
```http
833844
GET /articles?include=author&fields[articles]=title,body&fields[people]=name
834845
```
835846

847+
An example which includes [relationship attributes]:
848+
849+
```text
850+
GET /articles?include=author,publications&fields[articles]=title,links.publications.publication_type&fields[people]=name
851+
```
852+
836853
### Sorting <a href="#fetching-sorting" id="fetching-sorting" class="headerlink"></a>
837854

838-
A server **MAY** choose to support requests to sort resource collections
839-
according to one or more criteria ("sort fields").
855+
A server **MAY** choose to support requests to sort primary resource collections
856+
and linkage object arrays according to one or more criteria ("sort fields").
840857

841858
> Note: Although recommended, sort fields do not necessarily need to
842-
correspond to resource attribute and association names.
859+
correspond to names of [resource attribute], relationships and
860+
[relationship attributes].
843861

844862
> Note: It is recommended that dot-separated (U+002E FULL-STOP, ".") sort
845-
fields be used to request sorting based upon relationship attributes. For
846-
example, a sort field of `+author.name` could be used to request that the
847-
primary data be sorted based upon the `name` attribute of the `author`
848-
relationship.
863+
fields be used to request sorting of primary data based upon
864+
[resource attributes] of related resources. For example, a sort field of
865+
`+author.name` could be used to request that the primary data be sorted
866+
based upon the `name` attribute of the `author` relationship.
849867

850-
An endpoint **MAY** support requests to sort the primary data with a `sort`
851-
query parameter. The value for `sort` **MUST** represent sort fields.
868+
An endpoint **MAY** support requests to sort objects constituting reposnse
869+
with a `sort[PATH]` query parameter. The value of `PATH` **MUST** represent
870+
path to the object being sorted within the response object. The value of
871+
`sort[PATH]` **MUST** represent sort fields.
852872

853-
```http
854-
GET /people?sort=+age
873+
> Note: It is recommended that dot-separated (U+002E FULL-STOP, ".") fields
874+
be used to define `PATH` to the object being sorted within the response object.
875+
876+
For example, to sort primary data:
877+
878+
```text
879+
GET /people?sort[data]=+age
855880
```
856881

857882
An endpoint **MAY** support multiple sort fields by allowing comma-separated
858883
(U+002C COMMA, ",") sort fields. Sort fields **SHOULD** be applied in the
859884
order specified.
860885

861-
```http
862-
GET /people?sort=+age,+name
886+
```text
887+
GET /people?sort[data]=+age,+name
863888
```
864889

865890
The sort order for each sort field **MUST** be specified with one of the
@@ -872,8 +897,8 @@ following prefixes:
872897
order, JSON API avoids setting requirements for the first character in sort
873898
field names.
874899

875-
```http
876-
GET /articles?sort=-created,+title
900+
```text
901+
GET /articles?sort[data]=-created,+title
877902
```
878903

879904
The above example should return the newest articles first. Any articles
@@ -889,6 +914,23 @@ parameter `sort`, the server **MUST** return elements of the top-level
889914
The server **MAY** apply default sorting rules to top-level `data` if
890915
request parameter `sort` is not specified.
891916

917+
> Note: It is recommended that dot-separated (U+002E FULL-STOP, ".") sort
918+
fields be used to request sorting of relationship linkage object arrays
919+
based upon [relationship attributes] or [resource attributes] of related
920+
resources. It is recommended that mixing of these two criteria be allowed
921+
in one sort request.
922+
923+
The following example (referring to the
924+
<a href="#document-structure-compound-documents">complete example document
925+
with multiple included relationships</a>) should return publications
926+
of the article sorted first by publication type ([relationship attribute])
927+
and then by publication name (related [resource attribute]),
928+
both in ascending alphabetical order:
929+
930+
```text
931+
GET /articles?sort[data.links.publications]=+data.links.publications.publication_type,+name
932+
```
933+
892934
### Pagination <a href="#fetching-pagination" id="fetching-pagination" class="headerlink"></a>
893935

894936
A server **MAY** choose to limit the number of resources returned in a response

0 commit comments

Comments
 (0)
0