Extend the capabilities of dynamic REST API serialization to incorporate downstream relations #17971
Labels
complexity: high
Expected to require a large amont of time and effort to implement relative to other tasks
status: under review
Further discussion is needed to determine this issue's scope and/or implementation
type: feature
Introduction of new functionality to the application
NetBox version
v4.1.6
Feature type
New functionality
Triage priority
I volunteer to perform this work (if approved)
Proposed functionality
NetBox v4.0 introduced support for dynamic serializer fields in the REST API. For example, a request for
GET /api/dcim/sites/?fields=id,name,status
will return only the listed fields for each site:Now that this mechanism is in place, we can extend REST API serializers to also support returning downstream-related objects (e.g. racks or devices within a site). These objects will not be part of the object representation by default, but can be enabled by inclusion in the
fields
query parameter as above.For example, retrieving a list of device interfaces along with their assigned IP addresses could be achieved by requesting
GET /api/dcim/interfaces/?device=123&fields=name,type,enabled,ip_addresses
, which return something like the following rough mock-up:Use case
This would provide more flexibility when consuming the REST API, affording the API client a limited ability to include immediately related objects and obviate the need (in some cases) to make additional requests.
While it should be pointed out that this FR does not seek to effectively replicate the full GraphQL API in REST form, it would likely serve many of the simpler use cases for GraphQL.
Database changes
N/A
External dependencies
N/A
The text was updated successfully, but these errors were encountered: