Sparse Fieldsets
Our API supports a subset of the json:api spec, including sparse fieldsets.
As noted in the json:api spec:
Apps can request that an endpoint return only specific fields in the response on a per-type basis by including a
fields[TYPE]
parameter.The value of the fields parameter MUST be a comma-separated (U+002C COMMA, “,”) list that refers to the name(s) of the fields to be returned. An empty value indicates that no fields should be returned.
An example:
GET /api/{adviceSetId}/advice?fields[variables]=id,value&fields[adviceset]=
This would return only the id
and value
properties for the variables[]
list.
{
...
variables: {
id: "abcde123456",
value: true
}
}
Note the request specified an empty list for the adviceset
field. With this configuration, our API will not return any fields for that property nor the adviceset
property itself.
Experience and Performance
Sparse fieldsets are useful for improving not only the developer experience (by shrinking the amount of data to look through) but also for improving performance by reducing the response payload size.
Updated 7 months ago