How to FETCH data from an API using JavaScript ↩️
#javascript #utorial #course
00:00:00 fetch
00:06:29 async/await
00:08:55 project
// fetch = Function used for making HTTP requests to fetch resources.
// (JSON style data, images, files)
// Simplifies asynchronous data fetching in JavaScript and
// used for interacting with APIs to retrieve and send
// data asynchronously over the web.
// fetch(url, {options})
async function fetchData(){
try{
const pokemonName = document.getElementById("pokemonName").value.toLowerCase();
const response = await fetch(`pokeapi.co/api/v2/pokemon/${pokemonName}`);
if(!response.ok){
throw new Error("Could not fetch resource");
}
const data = await response.json();
const pokemonSprite = data.sprites.front_default;
const imgElement = document.getElementById("pokemonSprite");
imgElement.src = pokemonSprite;
imgElement.style.display = "block";
}
catch(error){
console.error(error);
}
}
// fetch = Function used for making HTTP requests to fetch resources. // (JSON style data, images, files) // Simplifies asynchronous data fetching in JavaScript and // used for interacting with APIs to retrieve and send // data asynchronously over the web. // fetch(url, {options}) async function fetchData(){ try{ const pokemonName = document.getElementById("pokemonName").value.toLowerCase(); const response = await fetch(`pokeapi.co/api/v2/pokemon/${pokemonName}`); if(!response.ok){ throw new Error("Could not fetch resource"); } const data = await response.json(); const pokemonSprite = data.sprites.front_default; const imgElement = document.getElementById("pokemonSprite"); imgElement.src = pokemonSprite; imgElement.style.display = "block"; } catch(error){ console.error(error); } } Document Fetch Pokemon
Thanks, can you help me? I want the code to give me the logo
thank you for your video
in my bottom of the heart i really appreciate you. here lot of middle class student like me. your tutorial helped me alot without any fee. thanks keep going. i expected more tutorial from you😇😇😇😇
From the buttom of my heart, and on behalf of everyone. i would like to thank you so much bro….. been struggling for months with this!!!😭❤️🙏🏾. Hoping to receive a reactJS one. Once again, thank you.
bro you're a legend. thank you for making code easier to learn.
i watch many tutorials on this topic but didn't understand it thanks for your video now i am finally understand it
i really enjoy all of your videos bro, you helped me a lot with this course, thank you! Psd: lucario is my fav pokemon
amazing tutorial man thanks
PERFECT TIMINGGGG THANK YOUUUUUU
Amazing tutorial I’m gonna try this, style it nicely and flex on my class lmaooo
THIS IS THE BEST TUTORIAL IN KZhead ABOUT THIS. And my favorite pokemon is cyndaquil so when you said Typhlosion I was like whaaaaaaaaaaaaat! What are the odds? hahaha
Not only a progammer but also a pokemon fan.
Same 🙂
So what ?
@@alternate_fantasy ur mom
@@diegocamacho6060 dont be sad kid :( im sorry for your life
@@alternate_fantasy ur mom
Bro I made it 🤩🤩🤸♀🤸♀, the think is I just want to keep watching your videos. I thought I would never understand Java script.Hopefully this year I'm going to be able to make it! Send you a hug!
this isn't included in your full Javascript course but i appreciate your efforts for doing it seperate
His full Javascript course was made awhile ago, this is a new updated version of that course.
Thank you very helpful.
So nice
Super helpful
the things i need right on time 😊😊
This guy is a legend
thank U to much Mr.Pokemon🔥❤🔥
awesome, thanks bro 💕
loved the content man.
Thanks Bro
Thank you!
Keep the good work up! It would be so appreciated if you did a beginner course on Rust all love
The broest Bro I've ever had
To be honest I was about to look for JavaScript form, about fetching and yes good counter I found this video xD
it was amazing
I LOVE YOU BRO CODE 🤩🤩🤩
thank you alot
Cool
👍👍👍👍
Hi bro, are you going to do a go course in the future?
bro please do php crud operation video please make as soon as possible
Question: what if we would not prefer to use async and await? how do we display the image with the fetch?
Please teach us lua in 2024!!! thanks for your content
hello bro will their be any more videos on React JS?
You will make node is course?
cool
Hey Bro, this question has actually nothing to do with this video but I’ve got a project where I have to implement the best move of the computer in the game TicTacToe. I just started to learn java but that’s quite hard. Do you have some tips for me? The computer has to try to defeat me and block me by placing the symbol to places wherever I could win. I hope that you will answer. Hava a nice day.
If she aint into me like he is into Typhlosion, I don’t want it!
I wish I found Bro Code earlier in my ‘teaching myself to code’ journey
should we not add an else block after checking response.ok property?
For the first part, are the html and css files empty? I would assume so, but then how do you run JS in the console
are you able to teach php and sql
hey, can u do a ruby course ? pls
How can i access object in an api and display on html I'm getting type error 😢
is it possible to do sorting
Oh my god....what were the chances....even typhlosion is my favourite pokemon...
Code bro react bro.... My life bro.... My heart bro.... Plz bro do bro......
I wont text generating logo with AI
my favorite pokemon is breloom I like using him to kidnap other pokemon
NodeJS course pls
Dragonite :D
This comment was automated
Make on lua pls
Do python next😢
Sir bro node js please
Quite not fair for a very basic and general video got such views.
charizard
SpongeBob is still not a Pokemon lol 😂
Kotlin or Golang course please.
from today pikachu
(y) (y)