Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData paging with skip and top - how to know that there is no more data?

Tags:

odata

I have OData source, that implements $skip and $top parameters. There are x number of entities that are returned. Say, I have only 250 entities. And then I try to do the paging like this:

https://example.com/EntitySet?$top=30&$skip=220

If my skip goes beyond the number of total entities, I eventually get timeout from service.

Is there a parameter or data, that would inform me that there are no more items? Is there something that can/should be implemented on OData side, that gets returned instead of timeout?

like image 307
Tschareck Avatar asked Dec 23 '22 23:12

Tschareck


1 Answers

For OData 2.0 and OData 3.0 protocols: You should use: $inlinecount=allpages

http://services.odata.org/OData/OData.svc/Products$inlinecount=allpages&$top=5&$format=json

Identifies the first 5 Product Entries and includes a count of the total number of Product Entries.

For OData 4.0, you can read the nextLink annotation embeded in the response. (See example here)

4.5.5 Annotation odata.nextLink The odata.nextLink annotation indicates that a response is only a subset of the requested collection of entities or collection of entity references. It contains a URL that allows retrieving the next subset of the requested collection.

like image 75
Yoram Avatar answered May 22 '23 11:05

Yoram