Added a paged sequence.
This commit is contained in:
1 parent
2364e2d859
commit
318ab1974c
4 files changed
+314
-14
No files matched your search
@@ -71,19 +71,22 @@ The `ok` property throws for any other response. To handle those, switch over th
|
||||
|
||||
### Fetching More Pages
|
||||
|
||||
Lists are paged. Pass a page's `links.nextCursor` as the `cursor` of the next request:
|
||||
Lists are paged. Iterate a `PagedSequence` to fetch each page in turn:
|
||||
|
||||
```swift
|
||||
var apps: [Components.Schemas.App] = []
|
||||
var cursor: String?
|
||||
let pages = PagedSequence(links: \.links) { cursor in
|
||||
try await client.appsGetCollection(query: .init(limit: 200, cursor: cursor)).ok.body.json
|
||||
}
|
||||
|
||||
repeat {
|
||||
let page = try await client.appsGetCollection(query: .init(limit: 200, cursor: cursor)).ok.body.json
|
||||
var apps: [Components.Schemas.App] = []
|
||||
|
||||
for try await page in pages {
|
||||
apps += page.data
|
||||
cursor = page.links.nextCursor
|
||||
} while cursor != nil
|
||||
}
|
||||
```
|
||||
|
||||
To fetch pages yourself, pass a page's `links.nextCursor` as the `cursor` of the next request.
|
||||
|
||||
### Handling Rate Limits
|
||||
|
||||
Add `RateLimitMiddleware` before the authentication middleware to retry `429 Too Many Requests` responses:
|
||||
|
||||
Reference in new issue
Block a user