Status: Open
Status: Answered
Status: Closed
Status: Duplicate

Pagination in REST API (or limiting how many objects are returned in the JSON)

Posted Jul 14 by Hugh Ferguson.

For most implementations, this is probably not a big concern but has any thought been given to how you could paginate results using the REST API? I looked at the API guide and didn't see it. Example. Let's say you go to retrieve all children of a particular folder, and the folder has over 10,000 items in it. Very hypothetical I realize, but given that Content Server now (rightly) supports pagination in the UI, it is not unreasonable for a folder to end up with a large number of items in it. The request URL doesn't support a page, but I'm wondering if a page size is something you could pass in on the request header?<br/>

2 Answers

BEST ANSWER: As chosen by the author.

Hi Hugh,

In my experience so far, when bringing back nodes from a particular folder (nodes/{id}/nodes), I've used the page option in my query.

Whilst moderately expensive, you can get the list of all pages from the resulting JSON (page_total) and then reissue the query to get the specific page you need.

It's not pretty and I'm hoping that someone has come up with a better strategy, but it's worked for me pretty well so far.



BEST ANSWER: As chosen by the author.

Resources with large collections behind them should support paging. Like the "/api/v1/nodes/{id}/nodes". The request offers page and limit parameters to specify the "window to the collection" to receive. You should check the response for the actually used values of page and limit, because the server can apply some throttling, if you request too many items. If you need all children, you would have to request page by page until you reach the end detected by reaching either the page_total or total_count from the last response.

 You have subscribed and will receive email notifications of updates to this topic. To unsubscribe, uncheck the checkbox.


Related categories

Related tags

Your answer

To leave an answer, please sign in.