Problem
The current pagination system only supports page[number] + page[size] style (or user-implemented variants). Many REST APIs use fundamentally different strategies:
- Cursor-based:
?cursor=<opaque_token> — cursor returned in response body or Link header
- Offset/limit:
?offset=0&limit=100, ?skip=0&take=100
- Link header: RFC 5988
Link: <url>; rel="next" — next page URL provided by server
None of these fit the current Pagination trait cleanly, forcing every user to implement the trait from scratch.
Proposed additions
OffsetPagination
#[derive(Pagination)]
pub struct OffsetPagination {
offset: usize,
limit: usize,
pagination: PaginationRule,
}
// Generates: ?offset=0&limit=100, ?offset=100&limit=100, ...
CursorPagination
pub struct CursorPagination {
cursor_param: String, // query param name, e.g. "cursor", "after", "page_token"
cursor: Option<String>, // current cursor value extracted from response
pagination: PaginationRule,
}
Requires a mechanism for the caller to extract the next cursor from the response body or Link header. Propose a CursorExtractor trait:
pub trait CursorExtractor: Send + Sync {
fn extract(response_headers: &HeaderMap, response_body: &Value) -> Option<String>;
}
Link-header follower
Auto-detect RFC 5988 Link: <url>; rel="next" headers and follow them without any pagination configuration.
Notes
- All three strategies should be available as first-class types in
reqt::pagination, usable as drop-in replacements for RequestPagination on Api<P, ...>.
#[derive(Pagination)] proc macro should be extended to support the new variants.
Problem
The current pagination system only supports
page[number]+page[size]style (or user-implemented variants). Many REST APIs use fundamentally different strategies:?cursor=<opaque_token>— cursor returned in response body orLinkheader?offset=0&limit=100,?skip=0&take=100Link: <url>; rel="next"— next page URL provided by serverNone of these fit the current
Paginationtrait cleanly, forcing every user to implement the trait from scratch.Proposed additions
OffsetPaginationCursorPaginationRequires a mechanism for the caller to extract the next cursor from the response body or
Linkheader. Propose aCursorExtractortrait:Link-header follower
Auto-detect RFC 5988
Link: <url>; rel="next"headers and follow them without any pagination configuration.Notes
reqt::pagination, usable as drop-in replacements forRequestPaginationonApi<P, ...>.#[derive(Pagination)]proc macro should be extended to support the new variants.