Fieldsets
Sparse Fieldsets
You’ll get this for free. Given a serializer:
And the request:
The description
field will not be returned in the response.
Extra Fieldsets
The opposite of a “sparse fieldset” is an “extra fieldset”. Perhaps you have an attribute that is computationally expensive and should only be returned when explicitly requested. Perhaps the majority of your clients need the same fields (and can share the same cache) but one client needs extra data (and you’ll accept the cache miss).
To request an extra field, just specify it in your serializer:
In the URL, replace fields
with extra_fields
:
The net_worth
attribute will only be returned when explicitly
requested.
You may want to eager load some data only when a specific extra field is
requested. There’s a hook for this in your Resource
;