Instead of giving the client the ability to construct arbitrary queries / filtering (something better served by existing standards / specifications, e.g. OData and GraphQL), we could allow predefined composite filters in the API, each composed of one or more filter primitives.
For example:
/users
q: match('username', 'ipartial') or match('email', 'ipartial') or match('firstName', 'iword_start') or match('lastName', 'iword_start')
/products
q: match('sku', 'iexact') or match('name', 'iword_start') or match('description', 'iword_start')
This also supports the aliasing use case where you could easily define multiple filter parameters for the same property, e.g.:
/users
email: match('email', 'iexact')
email_partial: match('email', 'ipartial')
/products
sku: match('sku', 'iexact')
sku_partial: match('sku', 'ipartial')
Of course, this also forces us to have decoupled code between the declaration of filter parameters (currently the $properties argument) and the actual filtering (currently the filterProperty function). It'd be a good opportunity to get rid of inheritance of filter classes (mark as deprecated; to be removed in API Platform 3.0).
Related:
Instead of giving the client the ability to construct arbitrary queries / filtering (something better served by existing standards / specifications, e.g. OData and GraphQL), we could allow predefined composite filters in the API, each composed of one or more filter primitives.
For example:
/usersq:match('username', 'ipartial') or match('email', 'ipartial') or match('firstName', 'iword_start') or match('lastName', 'iword_start')/productsq:match('sku', 'iexact') or match('name', 'iword_start') or match('description', 'iword_start')This also supports the aliasing use case where you could easily define multiple filter parameters for the same property, e.g.:
/usersemail:match('email', 'iexact')email_partial:match('email', 'ipartial')/productssku:match('sku', 'iexact')sku_partial:match('sku', 'ipartial')Of course, this also forces us to have decoupled code between the declaration of filter parameters (currently the
$propertiesargument) and the actual filtering (currently thefilterPropertyfunction). It'd be a good opportunity to get rid of inheritance of filter classes (mark as deprecated; to be removed in API Platform 3.0).Related: