@@ -644,7 +644,7 @@ first or last character:
644
644
645
645
The following characters ** MUST NOT** be used in member names:
646
646
647
- - U+002B PLUS SIGN, "+" _ (used for ordering )_
647
+ - U+002B PLUS SIGN, "+" _ (has overloaded meaning in URL query strings )_
648
648
- U+002C COMMA, "," _ (used as a separator between relationship paths)_
649
649
- U+002E PERIOD, "." _ (used as a separator within relationship paths)_
650
650
- U+005B LEFT SQUARE BRACKET, "[ " _ (used in sparse fieldsets)_
@@ -982,7 +982,7 @@ responses, in accordance with
982
982
983
983
An endpoint ** MAY** return resources related to the primary data by default.
984
984
985
- An endpoint ** MAY** also support an ` include ` request parameter to allow the
985
+ An endpoint ** MAY** also support an ` include ` query parameter to allow the
986
986
client to customize which related resources should be returned.
987
987
988
988
If an endpoint does not support the ` include ` parameter, it ** MUST** respond
@@ -1060,9 +1060,9 @@ resource or relationship.
1060
1060
### <a href =" #fetching-sparse-fieldsets " id =" fetching-sparse-fieldsets " class =" headerlink " ></a > Sparse Fieldsets
1061
1061
1062
1062
A client ** MAY** request that an endpoint return only specific [ fields] in the
1063
- response on a per-type basis by including a ` fields[TYPE] ` parameter.
1063
+ response on a per-type basis by including a ` fields[TYPE] ` query parameter.
1064
1064
1065
- The value of the ` fields ` parameter ** MUST** be a comma-separated (U+002C
1065
+ The value of any ` fields[TYPE] ` parameter ** MUST** be a comma-separated (U+002C
1066
1066
COMMA, ",") list that refers to the name(s) of the fields to be returned.
1067
1067
1068
1068
If a client requests a restricted set of [ fields] for a given resource type,
@@ -1075,8 +1075,8 @@ Accept: application/vnd.api+json
1075
1075
```
1076
1076
1077
1077
> Note: The above example URI shows unencoded ` [ ` and ` ] ` characters simply for
1078
- readability. In practice, these characters must be percent-encoded, per the
1079
- requirements [ in RFC 3986 ] ( http://tools.ietf.org/html/rfc3986#section-3.4 ) .
1078
+ readability. In practice, these characters should be percent-encoded. See
1079
+ " [ Square Brackets in Parameter Names ] ( #appendix-query-details-square-brackets ) " .
1080
1080
1081
1081
> Note: This section applies to any endpoint that responds with resources as
1082
1082
primary or included data, regardless of the request type. For instance, a
@@ -1089,7 +1089,7 @@ A server **MAY** choose to support requests to sort resource collections
1089
1089
according to one or more criteria ("sort fields").
1090
1090
1091
1091
> Note: Although recommended, sort fields do not necessarily need to
1092
- correspond to resource attribute and association names.
1092
+ correspond to resource attribute and relationship names.
1093
1093
1094
1094
> Note: It is recommended that dot-separated (U+002E FULL-STOP, ".") sort
1095
1095
fields be used to request sorting based upon relationship attributes. For
@@ -1165,32 +1165,24 @@ particular link is unavailable.
1165
1165
Concepts of order, as expressed in the naming of pagination links, ** MUST**
1166
1166
remain consistent with JSON: API 's [ sorting rules] ( #fetching-sorting ) .
1167
1167
1168
- The ` page ` query parameter is reserved for pagination. Servers and clients
1169
- ** SHOULD** use this key for pagination operations.
1168
+ The ` page ` [ query parameter family ] is reserved for pagination. Servers and
1169
+ clients ** SHOULD** use these parameters for pagination operations.
1170
1170
1171
- > Note: JSON: API is agnostic about the pagination strategy used by a server.
1172
- Effective pagination strategies include (but are not limited to):
1173
- page-based, offset-based, and cursor-based. The ` page ` query parameter can
1174
- be used as a basis for any of these strategies. For example, a page-based
1175
- strategy might use query parameters such as ` page[number] ` and ` page[size] ` ,
1176
- an offset-based strategy might use ` page[offset] ` and ` page[limit] ` , while a
1177
- cursor-based strategy might use ` page[cursor] ` .
1178
-
1179
- > Note: The example query parameters above use unencoded ` [ ` and ` ] ` characters
1180
- simply for readability. In practice, these characters must be percent-encoded,
1181
- per the requirements in [ RFC 3986] ( http://tools.ietf.org/html/rfc3986#section-3.4 ) .
1171
+ > Note: JSON API is agnostic about the pagination strategy used by a server, but
1172
+ > the ` page ` query parameter family can be used regardless of the strategy
1173
+ > employed. For example, a page-based strategy might use query parameters such
1174
+ > as ` page[number] ` and ` page[size] ` , while a cursor-based strategy might use
1175
+ > ` page[cursor] ` .
1182
1176
1183
1177
> Note: This section applies to any endpoint that responds with a resource
1184
1178
collection as primary data, regardless of the request type.
1185
1179
1186
1180
### <a href =" #fetching-filtering " id =" fetching-filtering " class =" headerlink " ></a > Filtering
1187
1181
1188
- The ` filter ` query parameter is reserved for filtering data. Servers and clients
1189
- ** SHOULD** use this key for filtering operations.
1182
+ The ` filter ` [ query parameter family ] is reserved for filtering data. Servers
1183
+ and clients ** SHOULD** use these parameters for filtering operations.
1190
1184
1191
- > Note: JSON: API is agnostic about the strategies supported by a server. The
1192
- ` filter ` query parameter can be used as the basis for any number of filtering
1193
- strategies.
1185
+ > Note: JSON API is agnostic about the strategies supported by a server.
1194
1186
1195
1187
## <a href =" #crud " id =" crud " class =" headerlink " ></a > Creating, Updating and Deleting Resources
1196
1188
@@ -1809,9 +1801,43 @@ responses, in accordance with
1809
1801
1810
1802
## <a href =" #query-parameters " id =" query-parameters " class =" headerlink " ></a > Query Parameters
1811
1803
1812
- Implementation-specific query parameter names ** MUST** adhere to the same
1813
- constraints as [ member names] , with the additional requirement that they
1814
- ** MUST** contain at least one non a-z character (i.e., outside U+0061 to U+007A).
1804
+ ### <a href =" #query-parameters-families " id =" query-parameters-families " class =" headerlink " ></a > Query Parameter Families
1805
+ Although "query parameter" is a common term in everyday web development, it is
1806
+ not a well-standardized concept. Therefore, JSON: API provides its own
1807
+ [ definition of a query parameter] ( #appendix-query-details ) .
1808
+
1809
+ For the most part, JSON: API 's definition coincides with colloquial usage, and its
1810
+ details can be safely ignored. However, one important consequence of this
1811
+ definition is that a URL like the following is considered to have two distinct
1812
+ query parameters:
1813
+
1814
+ ```
1815
+ /?page[offset]=0&page[limit]=10
1816
+ ```
1817
+
1818
+ The two parameters are named ` page[offset] ` and ` page[limit] ` ; there is no
1819
+ single ` page ` parameter.
1820
+
1821
+ In practice, however, parameters like ` page[offset] ` and ` page[limit] ` are
1822
+ usually defined and processed together, and it's convenient to refer to them
1823
+ collectively. Therefore, JSON: API introduces the concept of a query parameter
1824
+ family.
1825
+
1826
+ A "query parameter family" is the set of all query parameters whose name starts
1827
+ with a "base name", followed by zero or more instances of empty square brackets
1828
+ (i.e. ` [] ` ) or square-bracketed legal member names. The family is referred to
1829
+ by its base name.
1830
+
1831
+ For example, the ` filter ` query parameter family includes parameters named:
1832
+ ` filter ` , ` filter[x] ` , ` filter[] ` , ` filter[x][] ` , ` filter[][] ` , ` filter[x][y] ` ,
1833
+ etc. However, ` filter[_] ` is not a valid parameter name in the family, because
1834
+ ` _ ` is not a valid [ member name] [ member names ] .
1835
+
1836
+ ### <a href =" #query-parameters-custom " id =" query-parameters-custom " class =" headerlink " ></a > Implementation-Specific Query Parameters
1837
+ Implementations ** MAY** support custom query parameters. However, the names of
1838
+ these query parameters ** MUST** come from a [ family] [ query parameter family ]
1839
+ whose base name is a legal [ member name] [ member names ] and also contains at least
1840
+ one non a-z character (i.e., outside U+0061 to U+007A).
1815
1841
1816
1842
It is ** RECOMMENDED** that a capital letter (e.g. camelCasing) be used to
1817
1843
satisfy the above requirement.
@@ -1962,6 +1988,10 @@ To do so, a server **MAY** define an internal mapping from query parameter names
1962
1988
to profile URIs. The profile URI for a query parameter name in this mapping
1963
1989
** MUST NOT** change over time.
1964
1990
1991
+ > Note: the server may choose to map all query parameter names from the same
1992
+ > [ family] [ query parameter family ] to one profile URI. Or, it may choose to map
1993
+ > only specific query parameter names.
1994
+
1965
1995
If a requested URL does not contain the ` profile ` query parameter and does
1966
1996
contain one or more query parameters in the server's internal mapping, the
1967
1997
server may act as though the request URL contained a ` profile ` query parameter
@@ -1970,23 +2000,23 @@ found in the server's internal mapping for the query parameters in use on the
1970
2000
request.
1971
2001
1972
2002
For example, the server might support a profile that defines a meaning for the
1973
- values of the ` filter ` query param. Then, it could define its internal
2003
+ values of the ` page[cursor] ` query param. Then, it could define its internal
1974
2004
param name to profile uri mapping like so:
1975
2005
1976
2006
``` json
1977
- { "filter " : " https://example.com/my-filter -profile" }
2007
+ { "page[cursor] " : " https://example.com/pagination -profile" }
1978
2008
```
1979
2009
1980
2010
Accordingly, a request for:
1981
2011
1982
2012
```
1983
- https://example.com/?filter =xyz
2013
+ https://example.com/?page[cursor] =xyz
1984
2014
```
1985
2015
1986
2016
would be interpreted by the server as:
1987
2017
1988
2018
```
1989
- https://example.com/?filter =xyz&profile=https://example.com/my-filter -profile
2019
+ https://example.com/?page[cursor] =xyz&profile=https://example.com/pagination -profile
1990
2020
```
1991
2021
1992
2022
@@ -2191,8 +2221,8 @@ objects. A profile **MUST NOT** define/assign a meaning to document members
2191
2221
in areas of the document reserved for future use by the JSON: API specification.
2192
2222
2193
2223
For example, it would be illegal for a profile to define a new key in a
2194
- document's [ top-level] [ top level ] object, or in a [ links object] , as JSON : API
2195
- implementations are not allowed to add custom keys in those areas.
2224
+ document's [ top-level] [ top level ] object, or in a [ links object] [ links ] , as
2225
+ JSON API implementations are not allowed to add custom keys in those areas.
2196
2226
2197
2227
Likewise, a profile ** MAY** assign a meaning to query parameters or parameter
2198
2228
values whose details are left up to each implementation, such as ` filter ` and
@@ -2326,6 +2356,51 @@ An error object **MAY** have the following members:
2326
2356
* ` meta ` : a [ meta object] [ meta ] containing non-standard meta-information about the
2327
2357
error.
2328
2358
2359
+ ## <a href =" #appendix " id =" appendix " class =" headerlink " ></a > Appendix
2360
+ ### <a href =" #appendix-query-details " id =" appendix-query-details " class =" headerlink " ></a > Query Parameters Details
2361
+ #### <a href =" #appendix-query-details-parsing " id =" appendix-query-details-parsing " class =" headerlink " ></a > Parsing/Serialization
2362
+ A query parameter is a name–value pair extracted from, or serialized into, a
2363
+ URI's query string.
2364
+
2365
+ To extract the query parameters from a URI, an implementation ** MUST** run the
2366
+ URI's query string, excluding the leading question mark, through the
2367
+ [ ` application/x-www-form-urlencoded ` parsing algorithm] ( https://url.spec.whatwg.org/#urlencoded-parsing ) ,
2368
+ with one exception: JSON: API allows the specification that defines a query
2369
+ parameter's usage to provide its own rules for parsing the parameter's value
2370
+ from the ` value ` bytes identified in steps 3.2 and and 3.3 of the ` application/x-www-form-urlencoded `
2371
+ parsing algorithm. The resulting value might not be a string.
2372
+
2373
+ > Note: In general, the query string parsing built in to servers and browsers
2374
+ > will match the process specified above, so most implementations do not need
2375
+ > to worry about this.
2376
+ >
2377
+ > The ` application/x-www-form-urlencoded ` format is referenced because it is
2378
+ > the basis for the ` a=b&c=d ` style that almost all query strings use today.
2379
+ >
2380
+ > However, ` application/x-www-form-urlencoded ` parsing contains the bizarre
2381
+ > historical artifact that ` + ` characters must be treated as spaces, and it
2382
+ > requires that all values be percent-decoded during parsing, which makes it
2383
+ > impossible to use [ RFC 3986 delimiter characters] ( https://tools.ietf.org/html/rfc3986#section-2.2 )
2384
+ > as delimiters. These issues motivate the exception that JSON: API defines above.
2385
+
2386
+ Similarly, to serialize a query parameter into a URI, an implementation ** MUST**
2387
+ use the [ the ` application/x-www-form-urlencoded ` serializer] ( https://url.spec.whatwg.org/#concept-urlencoded-serializer ) ,
2388
+ with the corresponding exception that a parameter's value — but not its name —
2389
+ may be serialized differently than that algorithm requires, provided the
2390
+ serialization does not interfere with the ability to parse back the resulting URI.
2391
+
2392
+ #### <a href =" #appendix-query-details-square-brackets " id =" appendix-query-details-square-brackets " class =" headerlink " ></a > Square Brackets in Parameter Names
2393
+ With [ query parameter families] [ query parameter family ] , JSON: API allows for
2394
+ query parameters whose names contain square brackets (i.e., U+005B "[ " and
2395
+ U+005D "] ").
2396
+
2397
+ According to the query parameter serialization rules above, a compliant
2398
+ implementation will percent-encode these square brackets. However, some URI
2399
+ producers — namely browsers — do not always encode them. Servers ** SHOULD**
2400
+ accept requests in which these square brackets are left unencoded in a query
2401
+ parameter's name. If a server does accept these requests, it ** MUST** treat the
2402
+ request as equivalent to one in which the square brackets were percent-encoded.
2403
+
2329
2404
[ top level ] : #document-top-level
2330
2405
[ resource objects ] : #document-resource-objects
2331
2406
[ attributes ] : #document-resource-object-attributes
@@ -2348,3 +2423,4 @@ An error object **MAY** have the following members:
2348
2423
[ error objects ] : #errror-objects
2349
2424
[ member names ] : #document-member-names
2350
2425
[ pagination ] : #fetching-pagination
2426
+ [ query parameter family ] : #query-parameters-families
0 commit comments