Rustango docs

Paginate a list view

Problem

You have a list endpoint and want to page through results without loading every row.

Solution

Read the page + size from the query string, clamp them, and translate to limit / offset on the queryset.

let page = params.page.max(1);
let size = params.size.clamp(1, 100);
let rows = Post::objects()
    .order_by(&[("id", true)])
    .limit(size)
    .offset((page - 1) * size)
    .fetch(&pool)
    .await?;

Link headers

The pagination module emits RFC 5988 Link headers for next/prev so API clients can follow them.