Mock Paginated Product List Response
Create a paginated JSON API response for a product catalog with meta information including total count, page number, and per-page limit.
Detailed Explanation
Paginated Product List
Pagination is essential for any API returning large collections. This mock generates a paginated product list response following the offset-based pagination pattern, which is the most widely used approach in REST APIs.
Schema Structure
{
"data": [
{
"id": "uuid",
"name": "string",
"price": "number",
"currency": "enum(USD,EUR,GBP,JPY)",
"inStock": "boolean",
"category": "enum(electronics,clothing,food,books)"
}
],
"meta": {
"total": 247,
"page": 1,
"perPage": 20,
"totalPages": 13
}
}
Pagination Meta Fields
| Field | Purpose |
|---|---|
total |
Total number of records across all pages |
page |
Current page number (1-indexed) |
perPage |
Number of items per page |
totalPages |
Calculated total pages (ceil(total / perPage)) |
Why Offset-Based Pagination?
Offset-based pagination is straightforward to implement and understand. Clients can jump to any page directly. However, it has drawbacks with large datasets (performance degrades at high offsets) and can produce inconsistent results when data changes between requests. For real-time data, consider cursor-based pagination instead.
Price Representation
Using a number type for price is acceptable in mock data, but in production you should consider using integer cents (e.g., 1999 for $19.99) or a Decimal type to avoid floating-point precision issues.
Use Case
E-commerce frontend teams can use this mock to build and test product listing pages with pagination controls, price formatting, stock indicators, and category filters without waiting for the catalog API.