Uninett / nav

Network Administration Visualized
GNU General Public License v3.0
182 stars 38 forks source link

Redundant inlining of netbox objects in /interface API endpoint #1742

Open lunkwill42 opened 6 years ago

lunkwill42 commented 6 years ago

When accessing the /interface API endpoint using a filter like ?netbox=42, every returned object inlines the details of netbox 42, which seems really redundant.

jmbredal commented 6 years ago

Hm. DRF does not have a way of specifying fields.

Two possible solutions:

1. Select fields

There are some libraries that have implemented this, for instance https://github.com/wimglenn/djangorestframework-queryfields . This enables the API user to manipulate the fields returned. However this is opt in so that if the user does nothing all fields will be returned.

This is an improvement of the API with no breaking changes.

2. Link to object

This involves using HyperlinkedModelSerializer as a way of displaying identity fields (replacing the id field with an url field) and related fields by linking to the api detail endpoint for that object.

This breaks the current flow of the API and thus requires us to increase the API version number. Users of the API that is used to finding serialized netbox data on the interface must now use one more request.

As a sidenote the version number should really be more based on semver than just a single number but that is a separate issue.