Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Link: pagination HTTP headers #1014

Closed
simonw opened this issue Oct 10, 2020 · 6 comments
Closed

Add Link: pagination HTTP headers #1014

simonw opened this issue Oct 10, 2020 · 6 comments

Comments

@simonw
Copy link
Owner

simonw commented Oct 10, 2020

Spun off from #782. These can go on all of the JSON endpoints that support pagination.

@simonw
Copy link
Owner Author

simonw commented Oct 10, 2020

The GitHub API has these:

link: <https://api.github.com/repositories/107914493/commits?page=2>; rel="next", <https://api.github.com/repositories/107914493/commits?page=46>; rel="last"

WordPress API: https://css-tricks.com/wp-json/wp/v2/posts

link: <https://css-tricks.com/wp-json/wp/v2/posts?page=2>; rel="next"

It also has these:

x-wp-total: 5162
x-wp-totalpages: 517

@simonw
Copy link
Owner Author

simonw commented Oct 10, 2020

This should be documented on https://docs.datasette.io/en/stable/json_api.html

@simonw
Copy link
Owner Author

simonw commented Oct 10, 2020

I'm just going to implement the 'next' one.

@simonw
Copy link
Owner Author

simonw commented Oct 10, 2020

I won't offer a total-number header. That's expensive to calculate - no need to calculate it unless it's explicitly asked for.

@simonw
Copy link
Owner Author

simonw commented Oct 10, 2020

First example page to add this to: ?_shape=array, e.g. https://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array

@simonw simonw closed this as completed in e34e849 Oct 11, 2020
@simonw
Copy link
Owner Author

simonw commented Oct 11, 2020

Demo using paginate-json:

% paginate-json 'https://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array' | jq '. | length' 
https://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Cd%2Cv
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Ch%2Cr
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Cl%2Cn
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Cp%2Cj
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Ct%2Cf
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=a%2Cx%2Cb
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=b%2Ca%2Cx
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=b%2Ce%2Ct
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=b%2Ci%2Cp
http://latest.datasette.io/fixtures/compound_three_primary_keys.json?_shape=array&_next=b%2Cm%2Cl
1001

New documentation: https://docs.datasette.io/en/latest/json_api.html#pagination

simonw added a commit that referenced this issue Oct 20, 2020
@simonw simonw added this to the 0.51 milestone Oct 23, 2020
simonw added a commit that referenced this issue Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant