Support for Etag and Last-Modified in API response #3910

Closed
opened 2025-12-29 18:31:56 +01:00 by adam · 3 comments
Owner

Originally created by @EppO on GitHub (Jul 29, 2020).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.7.12

Proposed Functionality

Implement Etag and/or Last-Modified response headers for the netbox API.
I would allow to reduce the load on the netbox API with the information provided by the client (etag and/or If-Modified-Since headers).

Use Case

Today, when you send a request to the netbox API, you don't get much information of the "freshness" of the data in the response headers:

> GET /api/virtualization/virtual-machines/?name=mytestvm HTTP/1.1
> Host: netbox.mycorp.com
> User-Agent: curl/7.64.1
> accept: application/json
> Authorization: token mysupersecrettoken
>
< HTTP/1.1 200 OK
< Server: nginx/1.10.2
< Date: Wed, 29 Jul 2020 00:53:13 GMT
< Content-Type: application/json
< Content-Length: 764
< Connection: keep-alive
< Vary: Accept, Cookie, Origin
< Allow: GET, POST, HEAD, OPTIONS
< API-Version: 2.7
< X-Frame-Options: SAMEORIGIN

Database Changes

None.

External Dependencies

Originally created by @EppO on GitHub (Jul 29, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.7.12 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Implement [Etag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Etag) and/or [Last-Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) response headers for the netbox API. I would allow to reduce the load on the netbox API with the information provided by the client (etag and/or If-Modified-Since headers). <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Today, when you send a request to the netbox API, you don't get much information of the "freshness" of the data in the response headers: ``` > GET /api/virtualization/virtual-machines/?name=mytestvm HTTP/1.1 > Host: netbox.mycorp.com > User-Agent: curl/7.64.1 > accept: application/json > Authorization: token mysupersecrettoken > < HTTP/1.1 200 OK < Server: nginx/1.10.2 < Date: Wed, 29 Jul 2020 00:53:13 GMT < Content-Type: application/json < Content-Length: 764 < Connection: keep-alive < Vary: Accept, Cookie, Origin < Allow: GET, POST, HEAD, OPTIONS < API-Version: 2.7 < X-Frame-Options: SAMEORIGIN ``` <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes None. <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies
adam added the type: feature label 2025-12-29 18:31:56 +01:00
adam closed this issue 2025-12-29 18:32:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 14, 2020):

Models in NetBox for which the latest modification time is tracked already report it in their API representations as the last_updated attribute. What is the proposed benefit of duplicating this in an HTTP response header?

@jeremystretch commented on GitHub (Aug 14, 2020): Models in NetBox for which the latest modification time is tracked already report it in their API representations as the `last_updated` attribute. What is the proposed benefit of duplicating this in an HTTP response header?
Author
Owner

@jeremystretch commented on GitHub (Sep 1, 2020):

I'm going to decline this for two reasons:

  1. Django REST Framework does not appear to provide built-in support for it, meaning that any solution would require a custom implementation or the introduction of a new dependency.
  2. Since determining the last_updated time requires retrieving the object from the database anyway, there's not much benefit to communicating this in a header. That is, making a HEAD request to check the last modified time would result in a similar amount of overhead to a normal GET request, at least without a significant amount of custom development.
@jeremystretch commented on GitHub (Sep 1, 2020): I'm going to decline this for two reasons: 1. Django REST Framework does not appear to provide built-in support for it, meaning that any solution would require a custom implementation or the introduction of a new dependency. 2. Since determining the `last_updated` time requires retrieving the object from the database anyway, there's not much benefit to communicating this in a header. That is, making a HEAD request to check the last modified time would result in a similar amount of overhead to a normal GET request, at least without a significant amount of custom development.
Author
Owner

@EppO commented on GitHub (Sep 1, 2020):

Models in NetBox for which the latest modification time is tracked already report it in their API representations as the last_updated attribute. What is the proposed benefit of duplicating this in an HTTP response header?

When netbox is used at scale during the VM provisioning (to get some VM facts for example), there is no current way to cache the response closer to the VM. I was thinking about putting a cache proxy in the region of the VM, talking with the central netbox instance in another region, but the lack of HTTP headers prevents any caching at the HTTP level. That's unfortunate.

@EppO commented on GitHub (Sep 1, 2020): > Models in NetBox for which the latest modification time is tracked already report it in their API representations as the `last_updated` attribute. What is the proposed benefit of duplicating this in an HTTP response header? When netbox is used at scale during the VM provisioning (to get some VM facts for example), there is no current way to cache the response closer to the VM. I was thinking about putting a cache proxy in the region of the VM, talking with the central netbox instance in another region, but the lack of HTTP headers prevents any caching at the HTTP level. That's unfortunate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3910