Prevent repeating GET parameters when paginating with api command#4559
Merged
Prevent repeating GET parameters when paginating with api command#4559
Conversation
Sixeight
reviewed
Oct 19, 2021
| } | ||
| } else { | ||
| requestPath, hasNextPage = findNextPage(resp) | ||
| requestBody = nil // prevent repeating GET parameters |
Contributor
There was a problem hiding this comment.
Wouldn't parameters other than page and per_page also be overwritten?
Contributor
Author
There was a problem hiding this comment.
@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"
Contributor
There was a problem hiding this comment.
Oh, I did not know that. Thanks!
samcoe
approved these changes
Oct 19, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4540