An open API service indexing awesome lists of open source software.

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

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);
}
```