implement Link headers for API pagination #1689

Closed
opened 2025-12-29 16:34:26 +01:00 by adam · 3 comments
Owner

Originally created by @nickzxcv on GitHub (Apr 22, 2018).

Issue type

[ X ] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.3.2

Description

https://github.com/digitalocean/netbox/issues/1483 and https://github.com/digitalocean/netbox/issues/1176 mention how API clients should handle pagination, and it can be implemented from the body information ("next", "previous") but the Python requests library makes it easier if the API response includes a Link header for pagination:
http://docs.python-requests.org/en/master/user/advanced/#link-headers
The Link header values could be the same as the "next" and "previous" values in the body and shouldn't need any database schema changes.

https://github.com/tbeadle/django-rest-framework-link-header-pagination seems to be one implementation of this for django that might be relevant to NetBox.

Originally created by @nickzxcv on GitHub (Apr 22, 2018). ### Issue type [ X ] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.3.2 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description https://github.com/digitalocean/netbox/issues/1483 and https://github.com/digitalocean/netbox/issues/1176 mention how API clients should handle pagination, and it can be implemented from the body information ("next", "previous") but the Python requests library makes it easier if the API response includes a Link header for pagination: http://docs.python-requests.org/en/master/user/advanced/#link-headers The Link header values could be the same as the "next" and "previous" values in the body and shouldn't need any database schema changes. https://github.com/tbeadle/django-rest-framework-link-header-pagination seems to be one implementation of this for django that might be relevant to NetBox.
adam closed this issue 2025-12-29 16:34:26 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 23, 2018):

What is preventing you from using the links provided in the response body?

@jeremystretch commented on GitHub (Apr 23, 2018): What is preventing you from using the links provided in the response body?
Author
Owner

@nickzxcv commented on GitHub (Apr 23, 2018):

I already am successfully (maybe my code could be cleaner?), but it would be nicer to take advantage of the Link header support in requests. My thinking was, requests does so much handy stuff automatically like JSON decoding, can it handle paginating automatically somehow too? It's not completely automatic, but it helps I think. It would also help to have a "last" url as well as "next" and "previous", but not nearly as useful since similar logic can be worked out with "next" becoming null I think.

@nickzxcv commented on GitHub (Apr 23, 2018): I already am successfully (maybe my code could be cleaner?), but it would be nicer to take advantage of the Link header support in requests. My thinking was, requests does so much handy stuff automatically like JSON decoding, can it handle paginating automatically somehow too? It's not completely automatic, but it helps I think. It would also help to have a "last" url as well as "next" and "previous", but not nearly as useful since similar logic can be worked out with "next" becoming null I think.
Author
Owner

@nickzxcv commented on GitHub (Apr 26, 2018):

I found out about pynetbox now and I think I should really just use that instead of writing my own function to handle the paginating (which also worked fine, anyway). So I will close this.

@nickzxcv commented on GitHub (Apr 26, 2018): I found out about pynetbox now and I think I should really just use that instead of writing my own function to handle the paginating (which also worked fine, anyway). So I will close this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1689