Pagination
Auto-pagination, async iteration, and manual paging with the Renta SDK.
All list methods in the Renta SDK return paginated results. The SDK supports three usage patterns.
Direct Access (Single Page)
Get a single page of results with pagination metadata:
const page = await renta.fleet.items.list({ limit: 10 });
console.log(page.data); // FleetItem[]
console.log(page.hasMore); // boolean
console.log(page.nextCursor); // string | null
// Fetch the next page manually
if (page.hasMore) {
const nextPage = await page.nextPage();
console.log(nextPage.data);
}Async Iteration (Auto-Pagination)
Iterate through all results across pages automatically:
for await (const item of renta.fleet.items.list({ limit: 10 })) {
console.log(item.name);
// Automatically fetches next pages as needed
}The SDK fetches the next page when you exhaust the current one. This is the recommended approach for processing all records.
Collect All
Fetch all results into a single array:
const allItems = await renta.fleet.items.list().toArray();
console.log(`Total items: ${allItems.length}`);Use toArray() with caution on large datasets. It loads all records into memory. For large collections, prefer async iteration.
Pagination Parameters
All list methods accept these parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 20 | Results per page (1–100) |
cursor | string | — | Cursor from previous response's nextCursor |
Response Shape
interface PaginatedResponse<T> {
data: T[]; // Array of results
hasMore: boolean; // Whether more pages exist
nextCursor: string | null; // Cursor for next page
nextPage(): Promise<PaginatedResponse<T>>; // Fetch next page
toArray(): Promise<T[]>; // Collect all results
[Symbol.asyncIterator](): AsyncIterator<T>; // Async iteration
}Example: Paginating Bookings
// Process all confirmed bookings in batches of 50
let processed = 0;
for await (const booking of renta.bookings.list({ status: 'confirmed', limit: 50 })) {
await processBooking(booking);
processed++;
}
console.log(`Processed ${processed} bookings`);Manual Cursor Pagination
For server-side APIs that need explicit cursor control:
async function getPage(cursor?: string) {
const page = await renta.fleet.items.list({
limit: 20,
cursor,
});
return {
items: page.data,
nextCursor: page.nextCursor,
hasMore: page.hasMore,
};
}
// First page
const page1 = await getPage();
// Next page
const page2 = await getPage(page1.nextCursor!);