How to FETCH data from an API using JavaScript ↩️

2024 ж. 12 Мам.
69 681 Рет қаралды

#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

    @BroCodez@BroCodez4 ай бұрын
    • Thanks, can you help me? I want the code to give me the logo

      @talebmine6562@talebmine656228 күн бұрын
  • thank you for your video

    @alextruong1826@alextruong1826Ай бұрын
  • 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😇😇😇😇

    @abinayag4050@abinayag40503 ай бұрын
  • 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.

    @user-rw4cj8hp1p@user-rw4cj8hp1p4 ай бұрын
  • bro you're a legend. thank you for making code easier to learn.

    @RJ100@RJ10023 күн бұрын
  • i watch many tutorials on this topic but didn't understand it thanks for your video now i am finally understand it

    @muhammadshazeel567@muhammadshazeel567Ай бұрын
  • i really enjoy all of your videos bro, you helped me a lot with this course, thank you! Psd: lucario is my fav pokemon

    @JorgeHernandez-fo5kl@JorgeHernandez-fo5kl4 ай бұрын
  • amazing tutorial man thanks

    @QuadriCSGO@QuadriCSGO3 ай бұрын
  • PERFECT TIMINGGGG THANK YOUUUUUU

    @4soulsz@4soulsz4 ай бұрын
  • Amazing tutorial I’m gonna try this, style it nicely and flex on my class lmaooo

    @moeyk97@moeyk972 ай бұрын
  • 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

    @eusoumateusrocha@eusoumateusrocha2 ай бұрын
  • Not only a progammer but also a pokemon fan.

    @yassinezammouri2955@yassinezammouri29554 ай бұрын
    • Same 🙂

      @Th3Coder@Th3Coder4 ай бұрын
    • So what ?

      @alternate_fantasy@alternate_fantasyАй бұрын
    • @@alternate_fantasy ur mom

      @diegocamacho6060@diegocamacho606019 күн бұрын
    • @@diegocamacho6060 dont be sad kid :( im sorry for your life

      @alternate_fantasy@alternate_fantasy19 күн бұрын
    • @@alternate_fantasy ur mom

      @diegocamacho6060@diegocamacho606019 күн бұрын
  • 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!

    @vallunacoder.wecodetogether@vallunacoder.wecodetogether3 ай бұрын
  • this isn't included in your full Javascript course but i appreciate your efforts for doing it seperate

    @Vincent_12770@Vincent_127704 ай бұрын
    • His full Javascript course was made awhile ago, this is a new updated version of that course.

      @TheBlueDude71@TheBlueDude714 ай бұрын
  • Thank you very helpful.

    @valenciawalker6498@valenciawalker6498Ай бұрын
  • So nice

    @haniehsolatpour8945@haniehsolatpour89452 күн бұрын
  • Super helpful

    @shafiulAlamShafi@shafiulAlamShafi3 ай бұрын
  • the things i need right on time 😊😊

    @ajayxoxo@ajayxoxo4 ай бұрын
  • This guy is a legend

    @addyjaime465@addyjaime4658 күн бұрын
  • thank U to much Mr.Pokemon🔥❤‍🔥

    @lounes03b99@lounes03b99Ай бұрын
  • awesome, thanks bro 💕

    @nopass6247@nopass62474 ай бұрын
  • loved the content man.

    @programmated_brian@programmated_brian4 ай бұрын
  • Thanks Bro

    @Erica-ti4ll@Erica-ti4ll4 ай бұрын
  • Thank you!

    @lakivicsa@lakivicsa2 ай бұрын
  • Keep the good work up! It would be so appreciated if you did a beginner course on Rust all love

    @gibbaren2552@gibbaren25524 ай бұрын
  • The broest Bro I've ever had

    @fume6970@fume69702 ай бұрын
  • To be honest I was about to look for JavaScript form, about fetching and yes good counter I found this video xD

    @drewxx8527@drewxx85274 ай бұрын
  • it was amazing

    @user-fs5np2et9g@user-fs5np2et9g4 ай бұрын
  • I LOVE YOU BRO CODE 🤩🤩🤩

    @G.R.B.000@G.R.B.0004 ай бұрын
  • thank you alot

    @muhammadyousaf2876@muhammadyousaf28762 ай бұрын
  • Cool

    @user-mk2md9pu5m@user-mk2md9pu5m4 ай бұрын
  • 👍👍👍👍

    @marouanebr409@marouanebr409Ай бұрын
  • Hi bro, are you going to do a go course in the future?

    @doronfeldman5152@doronfeldman51524 ай бұрын
  • bro please do php crud operation video please make as soon as possible

    @user-jd2tt1vx3s@user-jd2tt1vx3s4 ай бұрын
  • Question: what if we would not prefer to use async and await? how do we display the image with the fetch?

    @MiriamGordilloChavez@MiriamGordilloChavezАй бұрын
  • Please teach us lua in 2024!!! thanks for your content

    @EuBrasileiro@EuBrasileiro4 ай бұрын
  • hello bro will their be any more videos on React JS?

    @feelthesurge1003@feelthesurge10034 ай бұрын
  • You will make node is course?

    @ofekcohen6559@ofekcohen65594 ай бұрын
  • cool

    @ghost.-.1290@ghost.-.12904 ай бұрын
  • 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.

    @anonym-6114@anonym-61144 ай бұрын
  • If she aint into me like he is into Typhlosion, I don’t want it!

    @HuracanSeneca@HuracanSeneca4 ай бұрын
  • I wish I found Bro Code earlier in my ‘teaching myself to code’ journey

    @kyleshivers@kyleshivers4 ай бұрын
  • should we not add an else block after checking response.ok property?

    @2ameridiem@2ameridiem2 ай бұрын
  • 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

    @minh355@minh35513 күн бұрын
  • are you able to teach php and sql

    @maxknight8542@maxknight85424 ай бұрын
  • hey, can u do a ruby course ? pls

    @sr.pinheiro6386@sr.pinheiro63864 ай бұрын
  • How can i access object in an api and display on html I'm getting type error 😢

    @zyntaXmods@zyntaXmods3 ай бұрын
  • is it possible to do sorting

    @manueljoseph3528@manueljoseph352817 күн бұрын
  • Oh my god....what were the chances....even typhlosion is my favourite pokemon...

    @parikshitkolhe3295@parikshitkolhe3295Ай бұрын
  • Code bro react bro.... My life bro.... My heart bro.... Plz bro do bro......

    @l213dhanesh3@l213dhanesh34 ай бұрын
  • I wont text generating logo with AI

    @talebmine6562@talebmine656228 күн бұрын
  • my favorite pokemon is breloom I like using him to kidnap other pokemon

    @weemarb@weemarb4 ай бұрын
  • NodeJS course pls

    @Erica-ti4ll@Erica-ti4ll4 ай бұрын
  • Dragonite :D

    @user-vl9nt6mo9s@user-vl9nt6mo9s4 ай бұрын
  • This comment was automated

    @MjRaj-hx2cu@MjRaj-hx2cu4 ай бұрын
  • Make on lua pls

    @eagledeluxe826@eagledeluxe8264 ай бұрын
  • Do python next😢

    @gamingwithyoungtrouble1193@gamingwithyoungtrouble11934 ай бұрын
  • Sir bro node js please

    @KiNGgamer-km4zi@KiNGgamer-km4zi4 ай бұрын
  • Quite not fair for a very basic and general video got such views.

    @alternate_fantasy@alternate_fantasyАй бұрын
  • charizard

    @kichuofficial8887@kichuofficial88873 ай бұрын
  • SpongeBob is still not a Pokemon lol 😂

    @codeJourneyGuides@codeJourneyGuidesАй бұрын
  • Kotlin or Golang course please.

    @capslock3250@capslock32504 ай бұрын
  • from today pikachu

    @Mr-MITRA@Mr-MITRA2 ай бұрын
  • (y) (y)

    @marouanebr409@marouanebr409Ай бұрын
KZhead