Sparse Fieldsets and Partial Responses
Use this skill when clients need to select fields or embed related resources without abandoning REST. Defaults stay complete and predictable; shaping is opt-in.
1. Sparse fieldsets
GET /users/7?fields=id,name,email
- Whitelist selectable fields; always include
id. - Reject or explicitly ignore unknown fields — do not silently expose internals.
- JSON:API:
?fields[articles]=title&fields[people]=name.
2. Include / expand
GET /orders/42?include=customer,items
Without include, return IDs/links. Cap depth (1–2), whitelist relationships, limit count/bytes. Keep list-endpoint includes shallow; rate-limit heavy expand.
3. Caching
Cache keys / Vary must account for fields and include variance.
4. Quick checklist
- Complete default responses.
- Allowlisted
fields; alwaysid. - Allowlisted
includewith depth/count caps. - Document params in OpenAPI.
- Shallow expands on collections.
- Cache variance documented.
See reference.md and examples.md.