Paginating hotel list responses on your API website


This article explains how to add a paginating system for hotel list results using the cacheKey and  cacheLocation parameters.


Use a List or an Array to save the cacheKey and a List or an Array to save the cacheLocation.

For example, you have made the first list request, and you received the response for the first page, which also includes the cacheKey and cacheLocation for the second page.

Make two lists in which you will save the cacheKey and cacheLocation:

List<String> cacheKeyList = new ArrayList<String>();
cacheKeyList.add(cacheKey); // where cacheKey is being received in the Hotel List response and is used for requesting the next page

List<String> cacheLocationList = new ArrayList<String>();
cacheLocationList.add(cacheLocation); // where cacheLocation is being received in the Hotel List response and is used for requesting the next page

 By using cacheKeyList[0] and cacheLocationList[0] in your next Hotel List request, you will receive the response for page 2.

Now, for every request that you do, the cache keys and cache locations for every page are being stored in your list, and for example, if you are at page 5 and you want to go at page 3, all you have to do is make a request using cacheKeyList[1] and cacheLocationList[1].

Also, the lists should be reinitialized after about 30 minutes, as the cacheKey and cacheLocation will expire.

In addition to the above example, you will have to shorten the list to the size of the current page you're on because once you use the cache key and the cache location for a previous page than the one you're on, the new cache key and cache location that you will receive for the next page will be different from the one you had for that next page. For example:

You are on page 5 and you saved the cacheKey and cacheLocation for page 6 in  cacheKey[4] and cacheLocation[4]. You go to the previous page, which is page 4 using  cacheKey[2]  and cacheLocation[2]. You now have to delete all the records from the lists that are past [2] (3rd record in the list) before receiving the response of page 4. For example cacheKey[3] and cacheLocation[3] should not exist at this very moment. After this has been done, you will receive the response with page 4 of hotels and the cacheKey and cacheLocation for page 5, which will be added to cacheKey[3] and cacheLocation[3].

In order to get to the first page, you have to make the initial request, without the cacheKey and cacheLocation.

More information

Initial request without cacheKey and cacheLocation - used to request page 1 of hotels
cacheKey[0] , cacheLocation[0] - used to request page 2 of hotels
cacheKey[1] , cacheLocation[1] - used to request page 3 of hotels
cacheKey[2] , cacheLocation[2] - used to request page 4 of hotels


cacheKey[n] , cacheLocation[n] - used to request page n+2 of hotels


Please note that the example provided is written in Java and depending on the developing language you are using, this may not work. This should be used as a reference and not copy/pasted in your application.



Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request