Search, Filter & Sorting
Query your mock APIs with powerful search, filtering, and sorting capabilities
Query Capabilities
Mock API Builder supports advanced query parameters for searching, filtering, sorting, and paginating your dataβjust like production APIs. These features work out of the box for all endpoints.
Full-text search across all fields or specific properties
Filter by specific field values with multiple operators
Order results by any field in ascending or descending order
Search
Use the q parameter to search across all text fields:
Example: Search for users named "John"
GET /api/users?q=johnJavaScript Example:
Search within specific fields using field name as the parameter:
Search by name:
GET /api/users?name=johnSearch by email:
GET /api/users?email=gmail.comSearch by multiple fields:
GET /api/users?name=john&role=adminπ‘ Search Behavior
- β’ Case-insensitive: Searches are not case-sensitive
- β’ Partial matching: Matches substrings (e.g., "john" matches "Johnson")
- β’ Multiple fields: Generic
qsearches across all text fields
Filtering
Exact Match (Default)
GET /api/users?role=adminReturns only users where role equals "admin"
Greater Than (_gte)
GET /api/products?price_gte=100Returns products with price greater than or equal to 100
Less Than (_lte)
GET /api/products?price_lte=50Returns products with price less than or equal to 50
Not Equal (_ne)
GET /api/users?status_ne=inactiveReturns users where status is not "inactive"
Contains (_like)
GET /api/posts?title_like=tutorialReturns posts where title contains "tutorial"
Example: Active admin users
GET /api/users?role=admin&status=activeExample: Products in price range
GET /api/products?price_gte=50&price_lte=200JavaScript Example:
Sorting
Ascending Order (Default)
GET /api/users?_sort=nameSort users by name in ascending order (A-Z)
Descending Order
GET /api/users?_sort=name&_order=descSort users by name in descending order (Z-A)
Sort by Multiple Fields
GET /api/posts?_sort=createdAt,likes&_order=desc,descSort by creation date first, then by likes (both descending)
Latest Posts First
GET /api/posts?_sort=createdAt&_order=descHighest Rated Products
GET /api/products?_sort=rating&_order=descCheapest Products First
GET /api/products?_sort=price&_order=ascReact Example with Dynamic Sorting:
Pagination
Limit Results per Page
GET /api/users?_limit=10Return only 10 users
Page Number
GET /api/users?_page=2&_limit=10Return page 2 (users 11-20)
React Pagination Component:
Using Start and Limit
GET /api/users?_start=20&_limit=10Skip first 20 users, return next 10 (users 21-30)
Infinite Scroll Example:
Combining Query Parameters
Filter + Sort + Paginate
GET /api/products?category=electronics&price_lte=500&_sort=price&_order=asc&_limit=20Electronics under $500, sorted by price (lowest first), 20 per page
Search + Filter + Sort
GET /api/posts?q=tutorial&author=john&_sort=createdAt&_order=descSearch for "tutorial" posts by John, newest first
Complete Example with React:
Pagination Response Headers
Paginated responses include helpful headers:
X-Total-CountTotal number of records (useful for calculating total pages)
LinkLinks to first, prev, next, and last pages
Reading Headers in JavaScript:
Best Practices
- βAlways paginate large datasets to improve performance and user experience
- βUse appropriate page sizes (10-50 items is typical for lists)
- βCombine filters for precision rather than client-side filtering
- βSort on the server instead of sorting large arrays in the browser
- βDebounce search inputs to avoid excessive API calls while typing
- βCache results when appropriate to reduce API calls
- βProvide clear UI feedback for active filters and sort options
- βUse URL query parameters to make filter/search state shareable