Skip to content

Proper way to implement paging #993

Answered by neet
jibla asked this question in Q&A
Oct 12, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hello @jibla. As you pointed out, Mastodon returns information related to pagination including the next minId in the HTTP Link header, and Masto.js is currently not offering a API for directly referring response headers.

However, we instead offer a higher level abstraction. All methods named list() actually returns an object that we call Paginator that can not only behave like a Promise, but also as a AsyncIterator.

Here's a basic example that favourite all posts on your home feed by using for-await-of syntax:

for await (const statuses of masto.v1.timelines.home.list()) {
  for (const status of statuses) {
    await masto.v1.statuses.$select(status.id).favourite();
  }
}

or if you want to…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jibla
Comment options

Answer selected by jibla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants