Skip to content

Feature: cursor-based and offset/limit pagination strategies #54

Description

@ZialeHub

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-ideaDiscussion; or implementation attempt, to be reviewed before further workrustPull requests that update rust code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions