Generated API - Sorting
The generated API comes with built-in support for sorting.
Sorting uses the orderBy
parameter, which accepts an object with the name of the fields.
note
Amplication does not support sorting by fields of nested entities.
The
orderBy
parameter is available only on endpoints and queries that return a list of items. For example:/api/posts
or/api/posts/{id}/tags
Sorting Examples
The following examples get all posts sorted by the createdAt
field.
REST API
curl -X 'GET' \
'https://[server-url]/api/posts?orderBy%5BcreatedAt%5D=asc' \
-H 'accept: application/json'
GraphQL
query{
posts(
orderBy:{
createdAt:desc
}
){
id
title
}
}