-
Notifications
You must be signed in to change notification settings - Fork 6
Filtering, paginating and ordering results
Agustín Borrego edited this page Dec 6, 2022
·
1 revision
Silence provides all user-defined GET endpoints with automatic filtering, paging and ordering via URL query params:
-
_sort
determines the field by which the results will be ordered (default: order determined by the database) -
_order
determines the sorting order ("asc"
or"desc"
, default:"asc"
) -
_limit
determines the maximum amount of results to show (default: no limit) -
_page
determines the page of results to show (to be combined with_limit
for easy paging, default: 0) - All other query parameters will be interpreted as a field that has to be filtered on
For example:
Get all departments whose city
is Seville
:
GET /api/departments?city=Sevilla
(200 OK)
[
{
"departmentId": 1,
"city": "Seville",
"name": "Computer Science"
},
{
"departmentId": 4,
"city": "Seville",
"name": "Literature"
},
]
Get all departments whose city
is Seville
AND their name
is Literature
:
GET /api/departments?city=Seville&name=Literature
(200 OK)
[
{
"departmentId": 4,
"city": "Seville",
"name": "Literature"
}
]
Get all departments ordered by decreasing departmentId:
GET /api/departments?_sort=departmentId&_order=desc
(200 OK)
[
{
"departmentId": 4,
"city": "Seville",
"name": "Literature"
},
{
"departmentId": 3,
"city": "Manchester",
"name": "Artificial Intelligence"
},
{
"departmentId": 2,
"city": "New York",
"name": "Physics"
},
{
"departmentId": 1,
"city": "Seville",
"name": "Computer Science"
}
]
Get the second page of the previous query, with 2 results per page:
GET /api/departments?_sort=departmentId&_order=desc&_limit=2&_page=1
(200 OK)
[
{
"departmentId": 2,
"city": "New York",
"name": "Physics"
},
{
"departmentId": 1,
"city": "Seville",
"name": "Computer Science"
}
]
These parameters can be combined in any way and work for all GET endpoints.
Silence is built and maintained by the DEAL Research Group at the University of Seville.