Pagination
Soxom supports cursor-based and offset-based pagination with automatic iteration.
Supported Types
Section titled “Supported Types”| Type | Description | Use Case |
|---|---|---|
cursor | Token or ID marking position | Recommended for most APIs |
offset | Traditional offset/limit | Legacy APIs, simple use cases |
Configuration
Section titled “Configuration”Global Settings
Section titled “Global Settings”pagination: # Default pagination type for all list endpoints default_type: cursor
# Define pagination schemes schemes: cursor: cursor: request_param: after # Query param for cursor response_property: next_cursor # Response field with next cursor limit: request_param: limit default: 20 max: 100 has_more: response_property: has_more # Boolean indicating more results
offset: offset: request_param: offset limit: request_param: limit default: 20 total: response_property: total # Total count of resultsCursor Pagination
Section titled “Cursor Pagination”Best for large datasets and real-time data.
pagination: schemes: cursor: cursor: request_param: after response_property: next_cursor # Or use last item's ID: # response_property: data[-1].id limit: request_param: limit default: 20 max: 100 has_more: response_property: has_moreExpected API Response:
{ "data": [...], "next_cursor": "cursor_abc123", "has_more": true}Offset Pagination
Section titled “Offset Pagination”Traditional pagination with page numbers.
pagination: schemes: offset: offset: request_param: offset limit: request_param: limit default: 20 total: response_property: totalExpected API Response:
{ "data": [...], "total": 150, "offset": 0, "limit": 20}Per-Endpoint Configuration
Section titled “Per-Endpoint Configuration”Use the x-soxom-pagination extension in your OpenAPI spec:
paths: /users: get: x-soxom-pagination: type: cursor cursor: $request.after results: $response.data has_more: $response.has_more parameters: - name: after in: query schema: type: string - name: limit in: query schema: type: integer default: 20 responses: "200": content: application/json: schema: $ref: "#/components/schemas/UserListResponse"
/products: get: x-soxom-pagination: type: offset results: $response.data total: $response.totalExtension Properties
Section titled “Extension Properties”| Property | Description |
|---|---|
type | cursor or offset |
cursor | JSONPath to cursor in request/response |
results | JSONPath to results array |
has_more | JSONPath to has_more boolean |
total | JSONPath to total count (offset only) |
Generated SDK Usage
Section titled “Generated SDK Usage”Auto-Iteration (Recommended)
Section titled “Auto-Iteration (Recommended)”Automatically fetches all pages:
// Iterate through all users automaticallyfor await (const user of client.users.list()) { console.log(user.name);}
// With filtersfor await (const user of client.users.list({ status: "active" })) { console.log(user.name);}
// Collect all into arrayconst allUsers = await client.users.list().toArray();# Iterate through all users automaticallyfor user in client.users.list(): print(user.name)
# With filtersfor user in client.users.list(status="active"): print(user.name)
# Collect all into listall_users = list(client.users.list())// Iterate through all usersiter := client.Users.List(ctx)for iter.Next() { user := iter.Current() fmt.Println(user.Name)}if err := iter.Err(); err != nil { log.Fatal(err)}Manual Pagination
Section titled “Manual Pagination”Control pagination manually:
// Get first pageconst page = await client.users.list({ limit: 10 });console.log(page.data);
// Check for more pagesif (page.hasMore) { const nextPage = await page.next(); console.log(nextPage.data);}
// Or use the cursor directlyconst page2 = await client.users.list({ limit: 10, after: page.nextCursor});# Get first pagepage = client.users.list(limit=10)print(page.data)
# Check for more pagesif page.has_more: next_page = page.next() print(next_page.data)
# Or use the cursor directlypage2 = client.users.list(limit=10, after=page.next_cursor)Response Structure
Section titled “Response Structure”Soxom expects list responses to have this structure:
Cursor Pagination
Section titled “Cursor Pagination”{ "data": [ { "id": "1", "name": "Alice" }, { "id": "2", "name": "Bob" } ], "next_cursor": "cursor_xyz", "has_more": true}Offset Pagination
Section titled “Offset Pagination”{ "data": [ { "id": "1", "name": "Alice" }, { "id": "2", "name": "Bob" } ], "total": 100, "offset": 0, "limit": 20}Best Practices
Section titled “Best Practices”- Prefer cursor pagination for better performance with large datasets
- Set reasonable defaults - 20-50 items per page is typical
- Set max limits to prevent abuse
- Use
has_moreinstead of checking cursor existence