Last active
September 29, 2022 17:23
-
-
Save konami12/81f7139b54517cb7ff5b2305e342ef7d to your computer and use it in GitHub Desktop.
fetch-generator-function.js
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
const fetch = require("node-fetch"); | |
/** | |
* Se realiza la peticion a la api solicitada | |
* | |
* @param {string} url Ruta correspondiente a la API. | |
* @return {object} | |
*/ | |
const requestData = async (url) => { | |
const REQUEST = await fetch(url); | |
const DATA = await REQUEST.json(); | |
return DATA; | |
}; | |
/** | |
* Genera las peticiones a la API | |
* | |
* @param {string} url Ruta del API | |
* @return {Promise} | |
*/ | |
async function* generateRequest(url) { | |
const ITEMS = await requestData(url); | |
let count = 0; | |
for (let item of ITEMS) { | |
yield item; | |
} | |
} | |
const API = "https://orca-api-pokemon.herokuapp.com"; | |
const GET_DATA = await generateRequest(`${API}/type/fire`); | |
let breakRequest = false; | |
do { | |
let {value , done} = await GET_DATA.next(); | |
console.log(value); | |
breakRequest = done; | |
} while(breakRequest !== true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment