-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow dynamic specification of fields to return in REST API #15087
Comments
Tentatively tagging this for v4.0 as it represents a major enhancement to the REST API. There's also probably some overlap with #13283. |
I've spent most of the day tackling this, and I'm happy to report that it went smoother than expected. Not only can serializer fields be dynamically toggled, we also obviate the need to explicitly prefetch fields on querysets. For example, in the FR branch,
As mentioned, this largely removes the need for "brief" mode (
I haven't bothered to include support for excluding fields, as I agree it's probably of very limited utility, though it remains possible.
I've limited this to first order fields on a serializer for now. While we could feasibly extend this, we should figure out the long-term plan for nested serializers first. IMO this would should be considered out of scope for this FR. |
…ds (#15122) * Enable dynamic field inclusion for REST API serializers * Recurse through nested serializer when resolving prefetches * Remove obsolete calls to prefetch_related() for API views * Remove support for brief_prefetch_fields viewset attribute * Rename query parameter * Fixes #15133: Fix FHRP group representation on assignments endpoint under brief mode (#15134) * Fixes #15133: Fix FHRP group representation on assignments endpoint under brief mode * Update API test * Restore get_queryset() on BriefModeMixin, minus prefetch logic * get_prefetches_for_serializer() should reference serializer field source if set
NetBox version
v3.7.2
Feature type
Change to existing functionality
Proposed functionality
Allow dynamically specifying which fields to return in REST APIs, something like ?fields=a,b,c or ?exclude=e,f. Similar to GraphQL how you can only return the fields you specifically need. There are several projects that do this - they are at different levels of maintainership so might make sense to just roll our own:
These offer differing levels of functionality:
?fields=
?exclude=
we probably don't need this?fields='front_port__name,...
we probably don't need thisUse case
This has several advantages:
Database changes
None
External dependencies
Potential to use external library, but we may want to just roll our own.
The text was updated successfully, but these errors were encountered: