You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes usage of fields parameter to be json:api spec compliant (#904)
* Changes the use of fields query string parameter to be json:api spec compliant.
Before we'd accept a relationship path between the square brackets and would only allow attribute names in the value. Now we expect a resource type between square brackets and the value can contain both attributes and relationships.
* Fixed: pass ID attribute in ResourceDefinition callback for relationships.
As an alternative to returning all attributes from a resource, the `fields` query string parameter can be used to select only a subset.
4
-
This can be used on the resource being requested, as well as nested endpoints and/or included resources.
3
+
As an alternative to returning all fields (attributes and relationships) from a resource, the `fields[]` query string parameter can be used to select a subset.
4
+
Put the resource type to apply the fieldset on between the brackets.
5
+
This can be used on the resource being requested, as well as on nested endpoints and/or included resources.
5
6
6
7
Top-level example:
7
8
```http
8
-
GET /articles?fields=title,body HTTP/1.1
9
+
GET /articles?fields[articles]=title,body,comments HTTP/1.1
9
10
```
10
11
11
12
Nested endpoint example:
12
13
```http
13
-
GET /api/blogs/1/articles?fields=title,body HTTP/1.1
14
+
GET /api/blogs/1/articles?fields[articles]=title,body,comments HTTP/1.1
14
15
```
15
16
17
+
When combined with the `include` query string parameter, a subset of related fields can be specified too.
18
+
16
19
Example for an included HasOne relationship:
17
20
```http
18
-
GET /articles?include=author&fields[author]=name HTTP/1.1
21
+
GET /articles?include=author&fields[authors]=name HTTP/1.1
19
22
```
20
23
21
24
Example for an included HasMany relationship:
@@ -25,9 +28,12 @@ GET /articles?include=revisions&fields[revisions]=publishTime HTTP/1.1
25
28
26
29
Example for both top-level and relationship:
27
30
```http
28
-
GET /articles?include=author&fields=title,body&fields[author]=name HTTP/1.1
31
+
GET /articles?include=author&fields[articles]=title,body,author&fields[authors]=name HTTP/1.1
29
32
```
30
33
34
+
Note that in the last example, the `author` relationship is also added to the `articles` fieldset, so that the relationship from article to author is returned.
35
+
When omitted, you'll get the included resources returned, but without full resource linkage (as described [here](https://jsonapi.org/examples/#sparse-fieldsets)).
36
+
31
37
## Overriding
32
38
33
39
As a developer, you can force to include and/or exclude specific fields as [described previously](~/usage/resources/resource-definitions.md).
Copy file name to clipboardExpand all lines: docs/usage/resources/attributes.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ This can be overridden per attribute.
39
39
40
40
### Viewability
41
41
42
-
Attributes can be marked to allow returning their value in responses. When not allowed and requested using `?fields=`, it results in an HTTP 400 response.
42
+
Attributes can be marked to allow returning their value in responses. When not allowed and requested using `?fields[]=`, it results in an HTTP 400 response.
0 commit comments