I am very new to web services so please provide answer like to a complete beginner.
I am writing an app to consume json webservice data. But the service may return 15, 20, 200, 500, 1000, ... records.
I need to get them all.
The baseURI could be something like this:
http://api.service.com/json/cars/search?&c=suv&l=49.263569,-122.9847682&within=20&units=km
I know the service will return something like this:
{
"total_items": "205",
"page_number": "1",
"page_size": "10",
"page_count": "20",
"cars": {
"car": [
{ ... },
{ ... },
...
{ ... }
]
}
}
So, I can see that there is 10 records per page and there is total of 20 pages. But I know this only once I issue the first request to get the data.
Here is my question: What is the way to get all 20 pages from a desktop application that shows these records in a a form with a scrollable control.
I thought something like:
getResponse(url, 1); //get first page, this also gives me page_count from response
for (i := 2; i < page_count; i++){
getResponse(url, i); // loop through number of pages to get each page till the end
}
So, above, I pass my url and page_number I want. First time I want 1st page, then I loop through all pages to get rest of pages by passing next page_number in each request.
Would this be common approach? How would I do it otherwise if this is not how it should be done?
Note that I don't have some kind of paging system on form, it is just a scrollable view holding all the results.