Created
April 1, 2022 23:09
-
-
Save saitergun/f137356419f0b4f3c3c60e80581642ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<pre></pre> | |
<script src="https://unpkg.com/axios"></script> | |
<script> | |
const getUsers = async (initialUsers = [], page = undefined) => { | |
const nextUsers = [...initialUsers] | |
const config = { | |
params: { | |
'where[]': 'json->madde,like,%loji', | |
page | |
} | |
} | |
const response = await axios('https://sozluk-api.herokuapp.com/api/words', config) | |
const { current_page, last_page } = response.data.meta | |
nextUsers.push(...response.data.data.map((x) => x.id)) | |
document.querySelector('pre').innerHTML = `${nextUsers.length} row loaded` | |
if (last_page > current_page) { | |
return await getUsers(nextUsers, current_page + 1) | |
} | |
return nextUsers | |
} | |
try { | |
(async () => { | |
const allUsers = await getUsers() | |
console.log(allUsers) | |
})() | |
} catch (error) { | |
console.error('error', error) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment