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

How to paginate requests #139

Open
lengrongfu opened this issue Aug 27, 2022 · 5 comments
Open

How to paginate requests #139

lengrongfu opened this issue Aug 27, 2022 · 5 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@lengrongfu
Copy link
Contributor

Describe your request
A clear and concise description of what you need help with.

# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!

I found that setting paging parameters is currently only used when NewRESTClientForHost is initialized, how to make paging calls when getting data, such as getting List Project.

@lengrongfu lengrongfu added help wanted Extra attention is needed question Further information is requested labels Aug 27, 2022
@elenz97
Copy link
Collaborator

elenz97 commented Aug 31, 2022

Hey @lengrongfu, thanks for opening the issue.

Please have a look at the provided example on how to instantiate a client using the optional pagination options. The options specified there will be passed to the Harbor API when calling the desired method, regardless of whether the client has been instantiated using NewRESTClient() or NewRESTClientForHost(). Only when leaving out the *config.Options{} entirely, the default values will be used.

HTH

@lengrongfu
Copy link
Contributor Author

According to your example, this can only show 100 pieces of data, the interface cannot obtain the data on the second page

@elenz97
Copy link
Collaborator

elenz97 commented Sep 5, 2022

Hey @lengrongfu, sadly, the API usage example is a bit misleading. With #145, it should be a lot more clearer on how to instantiate a client. Just for the record: Specifying options.PageSize: 100 when instantiating a client does not mean only 100 entries will be returned by the API. Instead, the parameters will be used to iterate until the count of all objects (using the X-Total-Count header) is reached. This was added in #141

@hunjixin
Copy link

Hey @lengrongfu, thanks for opening the issue.

Please have a look at the provided example on how to instantiate a client using the optional pagination options. The options specified there will be passed to the Harbor API when calling the desired method, regardless of whether the client has been instantiated using NewRESTClient() or NewRESTClientForHost(). Only when leaving out the *config.Options{} entirely, the default values will be used.

HTH

in the example, used internal package, how can user make this code work?

@hunjixin
Copy link

and why X-Total-Count is empty string,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants