users@jersey.java.net

[Jersey] Re: Pagination

From: Vetle Leinonen-Roeim <vetle_at_roeim.net>
Date: Thu, 11 Sep 2014 19:10:51 +0200

Hi,

A solution that we use, is to use the Link header. The request has a
page size and page start value, and we include Link headers in the
response for the client to navigate:

Link: http://example.com/orders?pageSize=10&pageStartIndex=0; rel="prev"
Link: http://example.com/orders?pageSize=10&pageStartIndex=1; rel="next"

If there are no previous or next pages, the links are of course not present.

This works well. The pageSize and pageStartIndex are used directly in
org.springframework.data.domain.PageRequest instances. PageStartIndex
defaults to zero, and pageSize to something appropriate, so the client
doesn't have to know about these things unless it wants to.

Regards,
Vetle


On 04.09.14 22:01, Nishant Chandra wrote:
> Hi,
>
> I have been trying to find a good way to implement pagination for an API
> and came across few options e.g. use headers or query params.
>
> Has anyone tried this with Jersey (in combination with Spring JPA) ? Any
> pointers to a sample code will be helpful.
>
> Thanks,
> Nishant
>