How to sort results?
It is possible order the results retrieved by DB2Rest using the sort request parameter. This will apply ORDER BY
on the generated SQL query. The general syntax of the sort parameter is shown below:
info
sort=[Column_name];[Sort_Direction],[Column_name];[Sort_Direction],[Column_name];[Sort_Direction]...
The sort parameter takes a list of Column_name and optional Sort_Direction separated by ,.
tip
Sort_Direction
- has two values
ASC(Ascending) andDESC(Descending). ASCis the default value.
- cURL
- HTTPie
curl --request GET \
--url 'http://localhost:8080/film?sort=title,rental_duration;desc' \
--header 'User-Agent: insomnia/8.6.1'
http GET 'http://localhost:8080/film?sort=title,rental_duration;desc' \
User-Agent:insomnia/8.6.1
In the above example, films are sorted by the column title in ascending order and then by column rental_duration
in descending order.