Skip to content

Commit 032d7d8

Browse files
committed
docs: add cursor pagination docs [CAPI-2342]
1 parent 5cb8f53 commit 032d7d8

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)
@@ -133,6 +134,7 @@ In order to get started with the Contentful JS library you'll need not only to i
133134
- [Your first request](#your-first-request)
134135
- [Using this library with the Preview API](#using-this-library-with-the-preview-api)
135136
- [Authentication](#authentication)
137+
- [Cursor-based pagination](#cursor-based-pagination)
136138
- [Documentation & References](#documentation--references)
137139

138140
### Installation
@@ -227,6 +229,29 @@ Don't forget to also get your Space ID.
227229

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

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

0 commit comments

Comments
 (0)