expression

REST: list response envelope and end marker

A collection response can carry both items and continuation metadata. The shape here always includes next_offset, with null meaning no more data. Document this convention and keep empty results successful when the collection exists. Do not equate an empty page with a missing resource. Standalone synthetic example. Expected stdout (not executed): empty: true end: true Common mistake: Changing the response from an array to an object without a compatibility plan.

Formal Syntax & Structure

rust syntaxrust
struct Page<T> { items: Vec<T>, next_offset: Option<usize> }

Working Example

Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    #[derive(Serialize)]    struct Page<T> { items: Vec<T>, next_offset: Option<usize> }    let page = Page::<u32> { items: vec![], next_offset: None };    let value = serde_json::to_value(page).unwrap();    println!("empty: {}", value["items"].as_array().unwrap().is_empty());    println!("end: {}", value["next_offset"].is_null());}
Rust Reference