Sorting

Last updated on
11 September 2019

JSON:API makes it possible to retrieve multiple resources in a single request, these routes are called "collection" routes. One can fetch a collection of resources by sending a GET request to the base resource route, e.g. GET /jsonapi/node/article and not including a UUID. By default, this will include all resources of the specified type.

Filtering and sorting are available by default on all standard resources.

Headers

The following headers are required on all GET request to get a proper JSON:API request and response.

  • Accept: application/vnd.api+json
  • Content-Type: application/vnd.api+json

The following header is needed for the examples to work:

  • Authorization: Basic YXBpOmFwaQ==

Sorting collections

Sorting by 'created'

Sort a collection by its "created" timestamp (defaults to sorting in ascending order)

SHORT
sort=created

NORMAL
sort[sort-created][path]=created

Sort by author's username

Sort a collection by author's username, in descending order. Note that the preceding "minus" sign (-) specifies descending order.

SHORT
sort=-uid.name

NORMAL
sort[sort-author][path]=uid.name
sort[sort-author][direction]=DESC

Sort by multiple fields

Sort a collection by multiple fields.

SHORT
sort=-created,uid.name

NORMAL
sort[sort-created][path]=created
sort[sort-created][direction]=DESC
sort[sort-author][path]=uid.name

Help improve this page

Page status: No known problems

You can: