Collections and Sorting

Last updated on
19 February 2018

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 follow 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 Examples

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

SHORT
sort=created

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

2. Sort a collection by author's username, in descending order

SHORT
sort=-uid.name

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

3. 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