@@ -320,6 +320,9 @@ they represent "[relationship attributes]" and may contain any valid JSON value.
320
320
Complex [ relationship attributes] ** MUST** abide by the same constraints as
321
321
[ complex resource attributes] .
322
322
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
+
323
326
> Note: Resource linkage in a compound document allows a client to link
324
327
together all of the included resource objects without having to ` GET ` any
325
328
relationship URLs.
@@ -817,49 +820,71 @@ GET /articles/1?include=author,comments,comments.author
817
820
818
821
### Sparse Fieldsets <a href =" #fetching-sparse-fieldsets " id =" fetching-sparse-fieldsets " class =" headerlink " ></a >
819
822
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.
822
826
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.
825
829
826
830
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.
828
840
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] :
831
842
832
843
``` http
833
844
GET /articles?include=author&fields[articles]=title,body&fields[people]=name
834
845
```
835
846
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
+
836
853
### Sorting <a href =" #fetching-sorting " id =" fetching-sorting " class =" headerlink " ></a >
837
854
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").
840
857
841
858
> 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] .
843
861
844
862
> 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.
849
867
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.
852
872
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
855
880
```
856
881
857
882
An endpoint ** MAY** support multiple sort fields by allowing comma-separated
858
883
(U+002C COMMA, ",") sort fields. Sort fields ** SHOULD** be applied in the
859
884
order specified.
860
885
861
- ``` http
862
- GET /people?sort=+age,+name
886
+ ``` text
887
+ GET /people?sort[data] =+age,+name
863
888
```
864
889
865
890
The sort order for each sort field ** MUST** be specified with one of the
@@ -872,8 +897,8 @@ following prefixes:
872
897
order, JSON API avoids setting requirements for the first character in sort
873
898
field names.
874
899
875
- ``` http
876
- GET /articles?sort=-created,+title
900
+ ``` text
901
+ GET /articles?sort[data] =-created,+title
877
902
```
878
903
879
904
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
889
914
The server ** MAY** apply default sorting rules to top-level ` data ` if
890
915
request parameter ` sort ` is not specified.
891
916
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
+
892
934
### Pagination <a href =" #fetching-pagination " id =" fetching-pagination " class =" headerlink " ></a >
893
935
894
936
A server ** MAY** choose to limit the number of resources returned in a response
0 commit comments