3 ms·
Yeah, it'd sure be nice if there was some way for the client to specify what data it wants.
by tedunangst 7y ago
Yeah, it'd sure be nice if there was some way for the client to specify what data it wants.
- ldiracdelta 7y agoI do that for my backends. On the HTTP request, the client sends a `?fields=encodeURIComponent(<JSON>)` query parameter to the server. If `fields` is present, then the API sends back the pruned version of the REST API. If `fields` is not present, then all the fields are sent back. Alternatively, you can prune the fields to a subset by default. The <JSON> looks like `{ foo=true, bar={baz=true}, bap=true} ` to imply the endpoint should send down field `foo`, nested object `bar` with only its field `baz` and the entire default nested object `bap`. I achieve this in Django Rest Framework by using meta-classes.