Response model filtering mechanism
Model filtering can be requested via fields
query string parameter:
fetch("/api/resource?fields=_links,items/id", { ... })
Fields parameter syntax summary
The format of the fields request parameter value is loosely based on XPath syntax. The supported syntax is summarized below, and additional examples are provided in the following section.
- Use a comma-separated list to select multiple fields.
-
Use
a/b
to select a field b that is nested within fielda
; usea/b/c
to select a field c nested within b.
Additional fields parameter syntax examples
The fields
request parameter value is a comma-separated list of fields, and each field is specified relative to the root of the response. Thus, if you are performing a list operation, the response is a collection, and it generally includes an array of resources. If you are performing an operation that returns a single resource, fields are specified relative to that resource. If the field you select is (or is part of) an array, the server returns the selected portion of all elements in the array.
Collection level examples:
Example | Effect |
---|---|
items |
Returns all elements in the items array, including all default fields in each element, but no other fields. |
_links,items |
Returns both the _links field and all elements in the items array. |
items/description |
Returns only the description field for all elements in the items array. Whenever a nested field is returned, the response includes the enclosing parent objects. The parent fields do not include any other child fields unless they are also selected explicitly. |
Resource level examples:
Example | Effect |
---|---|
description |
Returns the description field of the requested resource. |
description,_links_ |
Returns both the _links field and the description field of the requested resource. |
labels/serialNumber |
Returns the serialNumber sub-field of the labels object in the requested resource. |
labels, labels/serialNumber |
Same as labels . When combining generic and specific selectors a more generic one is used |