Prompt
API for search filter pagination export
Latest observation
Oct 8, 2026
OpenAI APIWeb search: off
Here’s a practical way to design an API that supports search, filtering, pagination, and export.
1) Common endpoint pattern
Use a single listing endpoint with query parameters:
GET /items?search=phone&status=active&category=electronics&page=1&limit=20&sort=createdAt:desc
Example query params
search— free-text searchstatus— exact filtercategory— exact filterfromDate,toDate— date rangepage— page numberlimit— items per pagesort— sorting field and direction
2) Response for pagination
Return both data and pagination metadata:
{
"data": [
{
"id": 1,
"name": "iPhone 15",
"status": "active"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 134,
"totalPages": 7
}
}
3) Search + filter behavior
Example:
GET /users?search=john&role=admin&isActive=true&page=2&limit=10
Rules:
searchapplies to name/email/phone, etc.- Filters apply as exact matches or ranges
- Combine them with
ANDlogic by default
4) Export support
For export, you usually have 2 options:
Option A: Same endpoint with export=true
GET /items?search=phone&status=active&export=true
Response:
- CSV/Excel file directly
- Usually ignores pagination and exports all matching records
Option B: Separate export endpoint
GET /items/export?search=phone&status=active&format=csv
This is cleaner for:
- CSV
- Excel
- large files
5) Recommended export response
CSV
Content-Type: text/csv
Content-Disposition: attachment; filename="items.csv"
Excel
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Disposition: attachment; filename="items.xlsx"
6) Example API design
List API
GET /api/products?search=apple&status=active&category=phones&page=1&limit=25&sort=name:asc
Export API
GET /api/products/export?search=apple&status=active&category=phones&format=csv
7) Best practices
- Validate all query params
- Default
page=1,limit=10or20 - Cap maximum
limitto prevent abuse - Return consistent pagination metadata
- Use cursor pagination if dataset is very large
- For export, use background jobs for large files
8) Sample full contract
Request
GET /api/orders?search=abc&status=paid&fromDate=2026-01-01&toDate=2026-01-31&page=1&limit=50&sort=createdAt:desc
Response
{
"data": [],
"pagination": {
"page": 1,
"limit": 50,
"total": 0,
"totalPages": 0
}
}
If you want, I can also give you:
- OpenAPI/Swagger spec
- Node.js/Express implementation
- Spring Boot implementation
- SQL query design for search/filter/pagination/export