Strapi Sort & Filter Syntax

Some attributes, such as strapi-filter and strapi-sort accept arguments arguments conforming to Strapi query string API parameters. The syntax for these attributes is identical to the Strapi query string API, except the identifier for the query string parameter is omitted. For example, consider the query string parameter sort=age , which might appear in a Strapi request like localhost:1337/api/people?sort=age. To achieve this in strapify you would give the attribute strapi-sort the argument age. Similarly for filters, the query string parameter filters[name][$eq]=Paul Dirac would become [name][$eq]=Paul Dirac when used with a the strapi-filter attribute.

When making a Strapi request, it is possible to include multiple of the same query string parameter. For example, you might have a request like localhost:1337/api/people?sort=name&sort=age:desc which would would sort the collection people by name and then by age descending. This is accomplished in Strapify by providing multiple arguments to the strapi-sort attribute with the value name | age:desc . Filters work similarly, if you had the request url localhost:1337/api/people?filters[$and][0][name][$eq]=Paul Dirac&filters[$and][1][age][$eq]=82, you would give strapi-filter the value [$and][0][name][$eq]=Paul Dirac | [$and][1][age][$eq]=82 .

There is one important difference between the Strapi query string API syntax and the Strapify syntax: equality operators must always be prefixed with [$eq] in Strapify arguments. For example, [name][$eq]=Paul Dirac is valid while [name]=Paul Dirac is not. This is due to the fact that while Strapi will allow the [$eq] part to be omitted when all other occurrences of the equality operator also omit it, Strapify uses the full [$eq]= syntax internally. If Strapify receives arguments using = instead of [$eq]= , invalid requests will be made and your Strapi data will not be fetched.