We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b5e4a56 commit 266f12dCopy full SHA for 266f12d
1 file changed
part9_Advanced/promises.js
@@ -78,6 +78,24 @@ p.then(() => {
78
})
79
80
81
+// Best way to handle api using promises
82
+function fetchData(url) {
83
+ return new Promise((resolve, reject) => {
84
+ fetch(url)
85
+ .then(response => response.json())
86
+ .then(data => resolve(data))
87
+ .catch(error => reject(error));
88
+ });
89
+}
90
+
91
+fetchData("https://fakestoreapi.com/products")
92
+ .then(data => console.log(data))
93
+ .catch(error => console.error("Error:", error));
94
95
96
97
98
99
// NOTE: Promises Quizes
100
101
// INFO: First Quiz
0 commit comments