The commercetools API provided predicates to query resources. Using the builders type safe predicates can be built.
For each resource that provides a query endpoint the request builders provide a WithQuery
method. The argument is a lambda function which provides the predicate builder. For each property of a resource the necessary methods are provided as well as the predicate operators.
Usage
_projectApiRoot.Customers().Get()
.WithQuery(q => q.FirstName().Is("Peter"));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.FirstName().IsNot("Peter"));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsLessThan(42));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsGreaterThan(42));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsLessThanOrEqual(42));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsGreaterThanOrEqual(42));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsNot(42));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.FirstName().Is("Peter").And(q.Version().IsLessThan(42)));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.FirstName().Is("Peter").Or(q.Version().IsLessThan(42)));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.FirstName().Is("Peter").And(q.Version().IsLessThan(42)).Not());
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsIn(new[] { 42, 43, 44 }));
_projectApiRoot.Customers().Get()
.WithQuery(q => q.Version().IsIn(new[] { 42, 43, 44 }).Not());
More examples can be found in the query test class