Skip to content

Filtering & Sorting

Filtering narrows a collection to the rows a client cares about; sorting decides their order. Both are query parameters on the collection, and a little convention keeps them readable.

The simplest, most discoverable form is one query parameter per field:

GET /articles?status=published&author=42

For ranges and operators, a common convention is a bracketed or suffixed operator:

GET /articles?createdAt[gte]=2026-01-01&views[gt]=1000

Keep the operator vocabulary small and documented (gte, lte, gt, lt, ne, in). Whatever you pick, apply it the same way on every collection.

Accept a sort parameter listing fields, with a leading - for descending:

GET /articles?sort=-createdAt,title

That reads as “newest first, then by title ascending”. Define which fields are sortable (sorting on an unindexed column can be expensive) and reject the rest with 400.

JavaScript
What does `?sort=-createdAt,title` mean?
Why allowlist filterable and sortable fields?
Where do filter and sort parameters belong?