-
Notifications
You must be signed in to change notification settings - Fork 0
GET (Query)
Bart Kardol edited this page Mar 31, 2019
·
3 revisions
Get requests can be done through calling the Query method on the ODataService instance. The Query method will return a IODataQuery<T>
which enables you to query your OData resource. When you're done querying either call getSingle() for a single object or getCollection() to retrieve a collection of objects.
Below some examples:
Expand
service.query().expand(['company', 'address']).getSingle(14);
Filter
Method 1 - Using a lambda
service.query().filter(f => f.equal('name', 'Snorvisable').and.greaterThan('age', 25)).getCollection();
Method 2 - Using a string
service.query().filter('name eq \'Snorvisable\' and age gt 25').getCollection();
Both examples above are doing exactly the same.
OrderBy
service.query().orderBy('age', ODataOrderDirection.descending).getCollection();
Select
service.query().select(['id', 'name', 'age']).getCollection();
Skip
service.query().skip(66).getCollection();
Top
service.query().top(33).getCollection();
Everything combined
service.query()
.expand(['company', 'address'])
.filter(f => f.equal('name', 'Snorvisable').and.greaterThan('age', 25))
.orderBy('age', ODataOrderDirection.descending)
.select(['id', 'name', 'age', 'company', 'address'])
.skip(66)
.top(33)
.getCollection();