json-api-server icon indicating copy to clipboard operation
json-api-server copied to clipboard

Sparse fields that are not included with being explicitly requested

Open tobyzerner opened this issue 1 year ago • 1 comments

The JSON:API spec on Sparse Fieldsets states:

If a client does not specify the set of fields for a given resource type, the server MAY send all fields, a subset of fields, or no fields for that resource type.

Currently, this implementation sends all fields. There should be the ability to mark a field as being excluded from this default response, such that it must be explicitly requested in order to be included.

I'm unsure of what a good method name for this would be though - open to suggestions...

Maybe:

Attribute::make('expensive')->onlyIfRequested();

tobyzerner avatar Aug 24 '23 10:08 tobyzerner

I think onlyIfRequested() makes sense. It also matches the terminology used one paragraph higher in the spec:

If a client requests a restricted set of fields for a given resource type [...]

(Emphasis mine)

Alternatively maybe onlyIfSpecified() could also match with "If a client does not specify the set of fields [...]" but I think it will be less clear.

bertramakers avatar Sep 25 '23 09:09 bertramakers