Advanced Features

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.

Search

Full-text search across all fields or specific properties

Filter

Filter by specific field values with multiple operators

Sort

Order results by any field in ascending or descending order

Search

Basic Search Query

Use the q parameter to search across all text fields:

Example: Search for users named "John"

GET /api/users?q=john

JavaScript Example:

javascript
Field-Specific Search

Search within specific fields using field name as the parameter:

Search by name:

GET /api/users?name=john

Search by email:

GET /api/users?email=gmail.com

Search 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 q searches across all text fields

Filtering

Filter Operators

Exact Match (Default)

GET /api/users?role=admin

Returns only users where role equals "admin"

Greater Than (_gte)

GET /api/products?price_gte=100

Returns products with price greater than or equal to 100

Less Than (_lte)

GET /api/products?price_lte=50

Returns products with price less than or equal to 50

Not Equal (_ne)

GET /api/users?status_ne=inactive

Returns users where status is not "inactive"

Contains (_like)

GET /api/posts?title_like=tutorial

Returns posts where title contains "tutorial"

Combining Multiple Filters

Example: Active admin users

GET /api/users?role=admin&status=active

Example: Products in price range

GET /api/products?price_gte=50&price_lte=200

JavaScript Example:

javascript

Sorting

Sort Parameters

Ascending Order (Default)

GET /api/users?_sort=name

Sort users by name in ascending order (A-Z)

Descending Order

GET /api/users?_sort=name&_order=desc

Sort users by name in descending order (Z-A)

Sort by Multiple Fields

GET /api/posts?_sort=createdAt,likes&_order=desc,desc

Sort by creation date first, then by likes (both descending)

Common Sorting Use Cases

Latest Posts First

GET /api/posts?_sort=createdAt&_order=desc

Highest Rated Products

GET /api/products?_sort=rating&_order=desc

Cheapest Products First

GET /api/products?_sort=price&_order=asc

React Example with Dynamic Sorting:

javascript

Pagination

Page-Based Pagination

Limit Results per Page

GET /api/users?_limit=10

Return only 10 users

Page Number

GET /api/users?_page=2&_limit=10

Return page 2 (users 11-20)

React Pagination Component:

javascript
Offset-Based Pagination

Using Start and Limit

GET /api/users?_start=20&_limit=10

Skip first 20 users, return next 10 (users 21-30)

Infinite Scroll Example:

javascript

Combining Query Parameters

Advanced Query Examples

Filter + Sort + Paginate

GET /api/products?category=electronics&price_lte=500&_sort=price&_order=asc&_limit=20

Electronics under $500, sorted by price (lowest first), 20 per page

Search + Filter + Sort

GET /api/posts?q=tutorial&author=john&_sort=createdAt&_order=desc

Search for "tutorial" posts by John, newest first

Complete Example with React:

javascript

Pagination Response Headers

Useful Response Headers

Paginated responses include helpful headers:

X-Total-Count

Total number of records (useful for calculating total pages)

Link

Links to first, prev, next, and last pages

Reading Headers in JavaScript:

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