Added a paged sequence.

This commit is contained in:
javier committed 2026-10-25 18:42:16 +01:00
1 parent 2364e2d859
commit 318ab1974c
4 files changed
+314 -14

No files matched your search

+10 -7
View File
@@ -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: