DrfResponseStrategy
Response strategy for the Django REST Framework (DRF) driver
Parses DRF PageNumberPagination responses:
{ "count": 100, "next": "http://api.example.com/items/?page=3", "previous": "http://api.example.com/items/?page=1", "results": [...]}DRF emits no current_page field in the body, so this strategy
derives the current page (and the page size) by inspecting the
next / previous URLs:
previous === null→ current page is 1.previousset but has no?page=Nparam → DRF omitspage=1from URLs when the previous page is the first, so we infer 2.previoushas?page=N→ current page is N + 1.
Similarly, perPage is parsed from any ?page_size=N query param on
next or previous, and lastPage is computed as
ceil(count / perPage). When perPage cannot be discovered (e.g. on a
single-page response that emits both URLs as null), perPage and
lastPage are left undefined.
Key paths are resolved through DrfResponseOptions, which defaults
data → 'results', total → 'count', nextPageUrl → 'next',
prevPageUrl → 'previous'. The current-page / per-page / last-page
paths default to empty strings — the strategy ignores options for
those slots and uses URL inspection instead.
Constructor
Section titled “Constructor”new DrfResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>Parse a DRF pagination response into a PaginatedCollection
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw API response body |
options |
ResponseOptions |
The response key name configuration |
Returns — A typed PaginatedCollection instance
