I am writing a client side java program for a Pageable Spring data resource The repository GET API is of the format:
public Page<Person> findByCountry(..., Pageable pageable);
I have created a pageable request of the format
Pageable pageable = new PageRequest(1, 40, new Sort("name"));
However, I would like to know how I can set this pageable into my http client
.
I am using HttpGet
and HttpPost
.
I googled a bit and found most links using spring rest controller. Can I not do this by using apache http client? Springs hateoas seems another option. But it would mean adding another jar to my client project. Is it just the question of how to set payload on a request?
Additionally, if there are better approaches let me know. I want to loop through all the pages till the data is exhausted.
Thanks.
The solution turned out to be simple. The mistake I was making was setting an parameters with non default names. Spring's rest api will create a pageable object if you pass correct params (As explained in 'HandlerMethodArgumentResolvers for Pageable and Sort' section of reference doc for Spring Data Repositories )
Pageable will be automatically created if the request has params with given names like page, size, etc.