Filtering
Ce contenu n’est pas encore disponible dans votre langue.
PhantomJSON supports filtering resources by field values using query parameters.
Simple Filtering
Section titled “Simple Filtering”Filter by exact match using the field name as a query parameter:
curl "https://api.phantomjson.app/v1/users?firstName=John"Operator Syntax
Section titled “Operator Syntax”Use bracket notation for comparison operators:
?field[operator]=valueSupported Operators
Section titled “Supported Operators”| Operator | Description | Example |
|---|---|---|
| (none) | Equals (default) | ?firstName=John |
neq |
Not equals | ?firstName[neq]=John |
gt |
Greater than | ?id[gt]=10 |
gte |
Greater than or equal | ?price[gte]=50 |
lt |
Less than | ?id[lt]=20 |
lte |
Less than or equal | ?price[lte]=200 |
in |
In list | ?id[in]=1,5,10 |
ct |
Contains | ?firstName[ct]=oh |
sw |
Starts with | ?firstName[sw]=Jo |
ew |
Ends with | ?lastName[ew]=son |
Examples
Section titled “Examples”Range Query
Section titled “Range Query”curl "https://api.phantomjson.app/v1/products?price[gte]=50&price[lte]=200"Contains
Section titled “Contains”curl "https://api.phantomjson.app/v1/users?firstName[ct]=oh"Multiple Values
Section titled “Multiple Values”curl "https://api.phantomjson.app/v1/todos?id[in]=1,5,10"Not Equals
Section titled “Not Equals”curl "https://api.phantomjson.app/v1/users?firstName[neq]=John"Combining Filters
Section titled “Combining Filters”Multiple filters are combined with AND logic:
curl "https://api.phantomjson.app/v1/products?category=smartphones&price[gte]=100"Filterable Fields
Section titled “Filterable Fields”Each resource has specific filterable fields:
| Resource | Filterable Fields |
|---|---|
| Users | id, firstName, lastName, email |
| Posts | id, userId, title |
| Comments | id, postId, name, email |
| Todos | id, userId, title, completed |
| Albums | id, userId, title |
| Photos | id, albumId, title |
| Products | id, name, category |
Case Sensitivity
Section titled “Case Sensitivity”All string filters are case-insensitive:
# These are equivalentcurl "https://api.phantomjson.app/v1/users?firstName=john"curl "https://api.phantomjson.app/v1/users?firstName=JOHN"