djangorestframework-link-header-pagination
Overview
Provide pagination using a Link HTTP header as described in GitHub's REST API documentation.
This pagination style accepts a single page number in the request query parameters. The response uses an HTTP header called Link to provide the URLs for the next, previous, first, and last pages. If you are using Python's Requests library to make the request, this header is automatically parsed for you as described here.
Request:
GET https://api.example.org/accounts/?page=4
Response:
HTTP 200 OK
Link: <https://api.example.org/accounts/>; rel="first", <https://api.example.org/accounts/?page=3>; rel="prev", <https://api.example.org/accounts/?page=5>; rel="next", <https://api.example.org/accounts/?page=11>; rel="last"
[
{
"id": 1,
"name": "item one",
},
...
]
Requirements
- Python (3.7+)
- Django (3.2+)
- Django REST Framework (3.11+)
Installation
Install using pip:
$ pip install djangorestframework-link-header-pagination
Setup
Add drf_link_header_pagination to your project's INSTALLED_APPS setting.
To enable the LinkHeaderPagination style globally, use the following configuration, modifying the PAGE_SIZE as desired:
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'drf_link_header_pagination.LinkHeaderPagination',
'PAGE_SIZE': 100
}
On GenericAPIView subclasses you may also set the pagination_class attribute to select LinkHeaderPagination on a per-view basis.
Other pagination classes that are available are:
LinkHeaderCursorPagination: This is similar to the normalCursorPaginationclass but using theLinkheader to return only thenextand/orprevlinks. Thefirstandlastlinks are unavailable.LinkHeaderLinkResponseCursorPagination: This is similar toLinkHeaderCursorPagination, but in addition to thenextand/orprevURL's being in theLinkheader, the content of the response body is updated to include them as well. The body will be an object with the keysnext(the next page's URL or None),previous(the previous page's URL or None), andresults(the original content of the body).LinkHeaderLimitOffsetPagination: Uses theLimitOffsetPaginationpagination class from DRF to supportoffsetandlimitparameters instead ofpageto indicate offset into the queryset.
Configuration
The configuration is the same as for
PageNumberPagination.
Testing
Use the excellent tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:
$ tox
Metadata
Release files for drf-link-header-pagination 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf_link_header_pagination-0.2.0.tar.gz | 7.7 kB | Without provenance | Details for drf_link_header_pagination-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_link_header_pagination-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for drf_link_header_pagination-0.2.0-py3-none-any.whl |
Total release size: 12.5 kB
Release files / drf_link_header_pagination-0.2.0.tar.gz
| Download URL | drf_link_header_pagination-0.2.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19446c5716a8b857f5e0ecbba39a49508a8e748ef51a8cfd6bd706090e97060c
|
|
BLAKE2b-256 checksum How to use checksums |
218692c695f5b0f55626dcf2db5d10977d284941b3adceb46d1067a787781382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.10
|
Release files / drf_link_header_pagination-0.2.0-py3-none-any.whl
| Download URL | drf_link_header_pagination-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9890a871803395544c5a0ee0665fc2d2701fcdf151570ed15c8b8d873aefe27d
|
|
BLAKE2b-256 checksum How to use checksums |
1ab20b73d23049cbe2936e35cf159f0840fca715966e4197d9a6418515d786eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.10
|
Security for drf-link-header-pagination 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.