@iflucianSubmitted almost 2 years ago
A nice way to practice and interact with 3rd-party APIs.
Any suggestions, tips or advice :) for improving the code are always welcome.
Thank you!
A nice way to practice and interact with 3rd-party APIs.
Any suggestions, tips or advice :) for improving the code are always welcome.
Thank you!
Hello!! š
You can add this:
const response= await fetch(urlAPI, {
method: "GET",
cache: "no cache",
});
The above code is so that it does not cache the tips, it seems that when I click on the button it only gives me a tip. Although this can also be solved by changing the url to https://api.adviceslip.com/advice/${id}
, and for each request they can change the id with a random number.
You can also implement an error handler, in case there is an error in the API.
try {
const response = await fetch(urlAPI, {
method: "GET",
cache: "no-cache",
});
if(!response.ok){
throw {
//
}
}
} catch (err) {
//
}
Hope am helpful.
Good job for completing this challenge.