Replies: 2 comments 1 reply
-
I assumed they are prev/next links, since that is how the links in these positions function on https://hypothes.is/search, google.com and a bunch of other sites.
Yes.
To summarize my comments from a call just now, I am wondering whether we should use offset/limit vs cursor-based pagination, or a hybrid (eg. caller specifies a cursor as a start point, then gets back a page of results plus links for the N pages after that). The current UI mockups all show groups with up to ~20 pages maximum. For this specific use case most groups do conform to that, but we do have a very small number of groups with thousands of members. For this use case we likely could get away with using an offset even with groups that have thousands of members, but there will be some overhead in a large group. When we come to re-implement activity pages however and support navigating through annotations or documents in groups that have millions of entries, we would have to either use a cursor or limit the number of pages the user can navigate through. For the use case of API users specifically iterating over all pages in a response, I think it would be a good idea to include an explicit |
Beta Was this translation helpful? Give feedback.
-
The current get-group-members API just returns a list of membership objects as a top-level JSON array:
Following the advice about pagination in JSON:API (see Pagination in the JSON:API spec) I propose to change the response format to this:
The
js-config
currently contains this for the get-group-members API:I propose to add the new
page[offset]
andpage[limit]
query params to thejs-config
, like this:It'll be up to the frontend to replace
{:offset}
and{:limit}
in the query param values with the desired offset and limit. The syntax comes from the URL Pattern API which we already use in some URLs injs-config
. It's not necessarily clear that this format was intended for query param values but it should work.Notes:
This would be a breaking change to the API so we'll use the presence of the
page[offset]
query param to trigger the new paginated version of the API. Without this query param the endpoint will return the legacy, non-paginated response.The frontend will have to use
page[offset]=0
to get the first page (and not the legacy non-paginated response). In future we intend to retire the legacy version of the API, when we do thatpage[offset]
can become optional and will default to0
.The
page[limit]
param will be optional. We'll pick default and maximum values for it, perhaps based on some testing of production response times (which'll require creating a test group with a lot of members in production).meta.page.total
is the total number of members in the group, which the frontend needs in order to be able to conveniently generate individual page links (see below) as well as to display this number in the UI. There's nothing in the JSON:API spec itself about providing the total length when returning paginated responses, this design is taken from the Collection Sizes section of the "Cursor Pagination" Profile to JSON:API.Note that this is the total number of items, not pages.
There's also an example of pagination on the JSON:API site that uses
meta.totalPages
for the total number of pages (as opposed to items). The example also has this to say:Our UI designs for the paginated version of the page have a pagination control that looks like this:
It's unclear in this design whether
<
and>
areprev
andnext
page links orfirst
andlast
.It's not shown in the designs but there'll presumably have to be some eliding of pages if there are too many of them.
The designs also contain a control for changing the page size.
The backend could also return links for each of the separate pages 1..8 and for prev/next/first/last pages. JSON:API allows this. But I think the frontend has all the information it needs (including the
js-config
and responsemeta
object) to generate these URLs itself and maybe it's better if the frontend does this.There are different ways to do pagination query params. For example you could do
page[n]=n
andpage[size]=50
. Orpage[after]
. I've gone with an offset and limit design that will translate directly toOFFSET
andLIMIT
in an SQL query. But I haven't given much thought to the pros and cons of different approaches here.Beta Was this translation helpful? Give feedback.
All reactions