Expand description
Offset pagination primitives: a query extractor for the request side and a uniform envelope for the response side.
ⓘ
#[Get("/")]
async fn list(&self, #[Query] page: PageParams, svc: Inject<UserService>)
-> Json<Page<User>>
{
let total = svc.count().await;
let rows = svc.list(page.limit(), page.offset()).await;
Json(Page::new(rows, page, total))
}PageParams deserializes straight from the query string (?page=2&per_page=50)
and is clamped on read, so a handler can never receive a zero page, a
negative offset, or an unbounded per_page that lets a client ask for the
whole table.
Structs§
- Page
- A page of results plus the metadata a client needs to walk the rest.
- Page
Params - Query parameters for an offset-paginated list endpoint.
Constants§
- DEFAULT_
PER_ PAGE - Default page size when the client omits
per_page. - MAX_
PER_ PAGE - Largest page size a client may request; larger values are clamped down so
per_pagecan never be weaponised into a full-table scan.