kalamata icon indicating copy to clipboard operation
kalamata copied to clipboard

Pagination support and also support ?whereIn= in the query string

Open nabilfreeman opened this issue 5 years ago • 0 comments

Hey there, we got pagination working in a nice way. We mentioned we were working on it here: #14

In your query string, you can specify ?page=1&page_size=250. The response will then be paginated to the first 250 results.

We have hardcoded id to be descending, so it's always newest to oldest. Let us know if this is ok, there is currently no user ordering option in Kalamata.

If you leave page blank, nothing will happen. It's required. If you leave page_size blank, it will default to 100. Supplying page_size without page will also do nothing If you set page_size to 99999 or something greater than the total pages, it will just return the full list on one page.

We took a leaf out of Wordpress wp-json's book for defining the next pages.

In this example, we'll query our API with /users?where={"type":"CUSTOMER"}&page=2&page_size=250.

In the response headers, you will get the following:

Header Value
x-next /users?where={"type":"CUSTOMER"}&page=3&page_size=250
x-prev /users?where={"type":"CUSTOMER"}&page=1&page_size=250
x-total-pages 43
x-total-items 10610

When you reach the first or last page, x-prev or x-next will be accordingly undefined. This is how you know you've reached the boundaries of the page list.

Would appreciate any feedback. We also bumped the version to 0.2 as although everything should continue working as normal for existing people not using ?page= there were some architecture changes and a new node module for query string manipulation.

nabilfreeman avatar Jul 17 '19 10:07 nabilfreeman