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

Pagination support? #2

Open
Nedlinin opened this issue Jan 15, 2021 · 3 comments
Open

Pagination support? #2

Nedlinin opened this issue Jan 15, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Nedlinin
Copy link

It looks like some endpoints limit you to say 20 results by default and might provide links to the next set of data within the result. Are there any plans to support this pagination today?

@jbeuckm jbeuckm added the enhancement New feature or request label Jan 15, 2021
@jbeuckm
Copy link
Owner

jbeuckm commented Jan 15, 2021

That seems like a good thing to support. PR welcome or maybe you could give an example of how to find the link to next page of results?

@Nedlinin
Copy link
Author

I've just started playing with the API to try to write something to help out my school teacher wife. I'm hoping to delve deeper into it this weekend and will hopefully be able to write up some examples then.

@Nedlinin
Copy link
Author

Nedlinin commented Jan 16, 2021

@jbeuckm : The example requested:

As can be seen in this snippet, if you request something that paginates and it has enough to require pagination you get a property called "links" with a "next" subprop. You simply need to rerequest the next level.

  {
    "message": [
     <message-objects>
    ],
    "links": {
      "self": "https://api.schoology.com/v1/messages/sent?start=0&limit=20",
      "next": "https://api.schoology.com/v1/messages/sent?start=20&limit=20"
    }
  }

The limit can actually be set (though I'm not sure what the values max is) with a simple query string so using the library as is I can do something like..

const messages = await client.makeRequest("get", `/messages/${box}/${urlAdditions}`)

where urlAdditions is

?start=0&limit=100

And I get up to 100 objects back.

I think simply adding a more accessible "start" and "limit" property to some calls is a great start and then perhaps adding a "autoPaginate" property to allow it to continue grabbing until the end is hit or we hit some maximum desired by the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants