محتوى الدرس
/*
Fetch API
- Return A Representation Of the Entire HTTP Response
*/
fetch("https://api.github.com/users/elzerowebschool/repos")
.then((result) => {
console.log(result);
let myData = result.json();
console.log(myData);
return myData;
})
.then((full) => {
full.length = 10;
return full;
})
.then((ten) => {
console.log(ten[0].name);
});
// const getData = (apiLink) => {
// return new Promise((resolve, reject) => {
// let myRequest = new XMLHttpRequest();
// myRequest.onload = function () {
// if (this.readyState === 4 && this.status === 200) {
// resolve(JSON.parse(this.responseText));
// } else {
// reject(Error("No Data Found"));
// }
// };
// myRequest.open("GET", apiLink);
// myRequest.send();
// });
// };
// getData("https://api.github.com/users/elzerowebschool/repos")
// .then((result) => {
// result.length = 10;
// return result;
// })
// .then((result) => console.log(result[0].name))
// .catch((rej) => console.log(rej));