Skip to content

Added example for "Sparse Fieldsets" #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions format/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,86 @@ COMMA, ",") list that refers to the name(s) of the fields to be returned.
If a client requests a restricted set of [fields], an endpoint **MUST NOT**
include additional [fields] in the response.

Basic request:

```http
GET /articles?include=author
```

```text
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": 1432306588,
"updated": 1432306589
},
"relationships": {
"author": {
"linkage": {
"id": 42, "type": "people"
}
}
}
},
"included": [
{
"type": "people",
"id": 42,
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
]
}
```

Request with `fields` parameter:

```http
GET /articles?include=author&fields[articles]=title,body&fields[people]=name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relationships must also be included in fields, even if they're specified via include. Therefore, the author field would have to be included in fields[articles] to get the response below.

In other words, the request would need to be:

GET /articles?include=author&fields[articles]=title,body,author&fields[people]=name

```

```text
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
},
"relationships": {
"author": {
"linkage": {
"id": 42, "type": "people"
}
}
}
},
"included": [
{
"type": "people",
"id": 42,
"attributes": {
"name": "John"
}
}
]
}
```

> Note: This section applies to any endpoint that responds with resources as
primary or included data, regardless of the request type. For instance, a
server could support sparse fieldsets along with a `POST` request to create
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy