Skip to content

Prevent repeating GET parameters when paginating with api command#4559

Merged
mislav merged 1 commit intotrunkfrom
api-pagination-fix
Oct 19, 2021
Merged

Prevent repeating GET parameters when paginating with api command#4559
mislav merged 1 commit intotrunkfrom
api-pagination-fix

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Oct 18, 2021

Fixes #4540

@mislav mislav requested a review from a team as a code owner October 18, 2021 18:43
@mislav mislav requested review from samcoe and removed request for a team October 18, 2021 18:43
}
} else {
requestPath, hasNextPage = findNextPage(resp)
requestBody = nil // prevent repeating GET parameters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't parameters other than page and per_page also be overwritten?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sixeight The thing is, GitHub API pagination responses include a "next" page link in its HTTP response headers. That link is guaranteed to always include all the parameters from the original query. Because we trust that the "next" link from the server is always correct, we don't have to repeat any GET parameters in subsequent requests.

For example:

$ gh api -i -X GET search/repositories -f q=cli -f per_page=10 | grep -i ^link
Link: <https://api.github.com/search/repositories?per_page=10&q=cli&page=2>; rel="next", <https://api.github.com/search/repositories?per_page=10&q=cli&page=100>; rel="last"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did not know that. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rest pagination does not work properly with page query parameter

3 participants