Closed
Description
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:
- https://stackoverflow.com/questions/27935558/dynamically-exclude-or-include-a-field-in-django-rest-framework-serializer
- https://github.com/rsinger86/drf-flex-fields
- https://github.com/csdenboer/drf-dynamic-serializers
- https://github.com/AltSchool/dynamic-rest
- https://github.com/imbokov/drf_dynamics
- https://timmytango.com/notes/excluding-fields-in-drf-serializers/
These offer differing levels of functionality:
- specify which fields to include:
?fields=
- specify which fields to exclude:
?exclude=
we probably don't need this - allow specifying field inclusion on FK references via double-underscore reference:
?fields='front_port__name,...
we probably don't need this
Use case
This has several advantages:
- Allow getting rid of brief API
- more flexible and performant as can only return fields you specifically want
- Works better / more flexible for the API for dropdown queries where the existing brief APIs don't quite fit
Database changes
None
External dependencies
Potential to use external library, but we may want to just roll our own.