Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
drf-link-header-pagination
Advanced tools
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",
},
...
]
Install using pip
:
$ pip install djangorestframework-link-header-pagination
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 normal CursorPagination
class but using the Link
header to return only the next
and/or prev
links. The first
and last
links are unavailable.LinkHeaderLinkResponseCursorPagination
: This is similar to
LinkHeaderCursorPagination
, but in addition to the next
and/or prev
URL's being in the Link
header, the content of the response body is updated to include them as well. The body will be an object with the keys next
(the next page's URL or None), previous
(the previous page's URL or None), and results
(the original content of the body).LinkHeaderLimitOffsetPagination
: Uses the LimitOffsetPagination
pagination class from DRF to support offset
and limit
parameters instead of page
to indicate offset into the queryset.The configuration is the same as for
PageNumberPagination
.
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
FAQs
Link Header Pagination for Django Rest Framework
We found that drf-link-header-pagination demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.