Skip to content

Commit 22d2ae6

Browse files
authored
add rest api sparse fieldsets (#491)
* add rest api sparse fieldsets * minor fixes
1 parent addfdb3 commit 22d2ae6

File tree

1 file changed

+20
-0
lines changed
  • docs/reference/server-adapters/api-handlers

1 file changed

+20
-0
lines changed

docs/reference/server-adapters/api-handlers/rest.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,26 @@ When including related resources, the response data takes the form of [Compound
620620
GET /api/post?include=author,comments
621621
```
622622
623+
#### Sparse Fieldsets
624+
625+
You can use the `fields[type]` query parameter to only include specified fields in the response. The value of the parameter is a comma-separated list of field names.
626+
627+
See the JSON:API specification for more details [Sparse Fieldsets](https://jsonapi.org/format/#fetching-sparse-fieldsets) and their [Examples](https://jsonapi.org/examples/#sparse-fieldsets)
628+
629+
##### Examples
630+
631+
1. Simple select
632+
633+
```ts
634+
GET /api/post?fields[post]=title,viewCount
635+
```
636+
637+
1. Also works with includes or relationships
638+
639+
```ts
640+
GET /api/post?include=author&fields[post]=title,viewCount&fields[author]=email
641+
```
642+
623643
### Creating a resource
624644
625645
A new resource can be created using the following endpoint:

0 commit comments

Comments
 (0)