From 025b3b5f2318e82ab26a348d72e2d66cbce0939a Mon Sep 17 00:00:00 2001 From: Maksim Kochkin Date: Fri, 22 May 2015 18:00:25 +0300 Subject: [PATCH] Added example for "Sparse Fieldsets" Example demonstrating how `fields` param works. --- format/index.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/format/index.md b/format/index.md index e488976a1..984383099 100644 --- a/format/index.md +++ b/format/index.md @@ -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 ``` +```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 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