Skip to content

Commit efd6a8c

Browse files
committed
docs: add cursor pagination docs [CAPI-2342]
1 parent f4b1cf9 commit efd6a8c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ JavaScript library for the Contentful [Content Delivery API](https://www.content
6868
- [Your first request](#your-first-request)
6969
- [Using this library with the Preview API](#using-this-library-with-the-preview-api)
7070
- [Authentication](#authentication)
71+
- [Cursor-based Pagination](#cursor-based-pagination)
7172
- [Documentation \& References](#documentation--references)
7273
- [Configuration](#configuration)
7374
- [Request configuration options](#request-configuration-options)
@@ -135,6 +136,7 @@ In order to get started with the Contentful JS library you'll need not only to i
135136
- [Your first request](#your-first-request)
136137
- [Using this library with the Preview API](#using-this-library-with-the-preview-api)
137138
- [Authentication](#authentication)
139+
- [Cursor-based pagination](#cursor-based-pagination)
138140
- [Documentation & References](#documentation--references)
139141

140142
### Installation
@@ -229,6 +231,29 @@ Don't forget to also get your Space ID.
229231

230232
For more information, check the [Contentful REST API reference on Authentication](https://www.contentful.com/developers/docs/references/authentication/).
231233

234+
### Cursor-based Pagination
235+
236+
Cursor-based pagination is supported on collection endpoints for entries and assets:
237+
238+
```js
239+
const response = await client.getEntriesWithCursor({ limit: 10 })
240+
console.log(response.items) // Array of items
241+
console.log(response.pages?.next) // Cursor for next page
242+
```
243+
244+
Use the value from `response.pages.next` to fetch the next page or `response.pages.prev` to fetch the previous page.
245+
246+
```js
247+
const nextPageResponse = await client.getEntriesWithCursor({
248+
limit: 10,
249+
pageNext: response.pages?.next,
250+
})
251+
252+
console.log(nextPageResponse.items) // Array of items
253+
console.log(nextPageResponse.pages?.next) // Cursor for next page
254+
console.log(nextPageResponse.pages?.prev) // Cursor for prev page
255+
```
256+
232257
## Documentation & References
233258
234259
- [Configuration](#configuration)

0 commit comments

Comments
 (0)