https://github.com/erfanium/page_iter
Iterate through paginated api results for Deno
https://github.com/erfanium/page_iter
Last synced: 11 months ago
JSON representation
Iterate through paginated api results for Deno
- Host: GitHub
- URL: https://github.com/erfanium/page_iter
- Owner: erfanium
- License: mit
- Created: 2021-08-04T13:51:57.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-04T14:40:08.000Z (almost 5 years ago)
- Last Synced: 2025-02-05T12:46:14.681Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://deno.land/x/page_iter@v1.0.0
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# page_iter
Iterate through paginated api results
## Example
```ts
interface Todo {
id: number;
title: string;
}
const fetchTodos: PagedHandler = async (page: number) => {
const response = await fetch(
`https://jsonplaceholder.typicode.com/todos?_start=${(page - 1) *
10}&_limit=10`,
);
const body: Todo[] = await response.json();
if (body.length === 0) {
return {
data: [],
nextPage: null,
};
}
return {
data: body,
nextPage: page + 1,
};
};
for await (const todo of pageIter(fetchTodos)) {
console.log(todo.id, todo.title);
}
```