Pagination & Filtering, what about the links?

Hi,
I have a question about what the contents of the ‘links’ should be when a combination of pagination and filtering is used.

Concrete: should the ‘next’ link also contain the filter parameters, or just (for example) ‘page[size]=10&page[number]=2’?
If the filter parameters are not part of the link, I guess they cannot be used to navigate through a filtered collection…

I think you are correct in this reading of the pagination and the general indifference of JSON:api on filtering, see 6.7 Filtering (using my specification reference, see PR). Or just look up Filtering (not as easy IMHO :slight_smile: )

The filter query parameter is reserved for this. It becomes a bit harder using a POST and a request body for filtering though (which is a proposal my team is looking to use).

There are a number of discussions here about filtering strategies that may be of interest as well.

I’d be interested to know what you come up with too!

The collection you are paginating is defined by the collection you’re addressing by the URL and any non-pagination parameters provided (filter, sort, or non-standard parameters). So the pagination links present in the top-level links` for a collection response should include all the required parameters.

In my implementation, I copy all the non-pagination parameters into all the links in my response rendering library, so it’s always handled the same way. The pagination support is responsible for providing any page[...] parameters needed for each of the links.

-Fred

1 Like

Thank you for the suggestions.
I will request the filter parameters to be copied to the pagination links (I am consuming this API).
This makes the most sense to me.