netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Modify REST API to allow selecting which fields to return in lieu of brief API

Open arthanson opened this issue 1 year ago • 1 comments

NetBox version

v3.6.5

Feature type

Change to existing functionality

Proposed functionality

It recently came up in discussion for another ticket the limitation of the brief APIs which are provided to return limited data from the full API for performance reasons for such things as selections when you don't need all the data. In the case under discussion the brief API didn't provide the fields needed and a potential suggestion was to convert those to GraphQL. This is open for discussion of a potential alternative where there are several libraries that allow specifying a ?fields=a,b,c to REST API call to limit which fields are returned (similar to GraphQL) which would replace the need for the brief APIs and also make them much more flexible.

Current libraries are listed below. Some of these are probably more complicated then our use cases (allowing specifying exclude as well as include fields and down to related models (a.b.c) Just allowing selecting fields is fairly small amount of code and could be just included without using a third-party library.

  • https://github.com/rsinger86/drf-flex-fields
  • https://github.com/ernestofgonzalez/django-dynamic-rest
  • https://gist.github.com/dgreisen-cfpb/10023365
  • https://github.com/AltSchool/dynamic-rest
  • https://github.com/wimglenn/djangorestframework-queryfields
  • https://github.com/dbrgn/drf-dynamic-fields

Use case

Replace the need for the brief APIs and allow them to be more flexible and optimized for each use-case.

Database changes

None

External dependencies

Potentially an external library or not as we could just pull in a small amount of code for this functionality.

arthanson avatar Nov 20 '23 17:11 arthanson

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

github-actions[bot] avatar Feb 19 '24 04:02 github-actions[bot]

I believe this is the FR we suspected already existed but for some reason could not find before opening #15087. This work has already been completed and will be included in the upcoming v4.0 release.

jeremystretch avatar Feb 20 '24 13:02 jeremystretch