Fetch API & Rendering Data with JavaScript

  Рет қаралды 122,857

Code Bushi

Code Bushi

Күн бұрын

In this video, we take a look at the browser's built in Fetch API to get some dummy data. We then map over that dummy data to create some HTML with Vanilla JavaScript and render it onto the screen.
Key Takeaways From The Video:
3:20 - The Fetch API returns a Promise, so you need to wait for the promise to resolve by using .then() after it.
4:16 - The Fetch API initially return a Response object, which will tell you the status code of the response among other details
5:15 - We need to run the .json() method on the response object to turn the response into more useful data. The .json() method will also return a promise, so we need to chain another .then() onto it.
8:10 - When using the Fetch API, it won't automatically throw all errors. You have to manually check to see if the response object has an "ok" property on it, and throw an error if it's not. This will help you catch things like a 404 error with the response.
11:11 - In order to render our data to the screen, we can use innerHTML or insertAdjacentHTML and insert an HTML string into an existing HTML element.
14:13 - Since the data we get back is an array, we can perform .map() on the array to loop over the data. We then use Template literals to construct our HTML string.
22:10 - With the Fetch API, you can also perform a POST request by adding additional options when making the request. Make sure to add the proper "headers" and use JSON.stringify() in the body of the request.
If this video was helpful, please like and subscribe! You can follow me on:
Twitter: / hunterhchang
codebushi.com

Пікірлер: 98
@OverwhelmingGrace
@OverwhelmingGrace Жыл бұрын
I really like the way you take this step by step from the ground up. I've worked with fetch before but found that I really did not understand how it worked.
@guchi3947
@guchi3947 2 жыл бұрын
I'm gonna cry, I have seen the light. Bless your soul, kind man.
@user-dr3rj3gt2b
@user-dr3rj3gt2b 3 жыл бұрын
GOAT! This guy explains everything better than any Udemy instructor
@afsanazamannipa7711
@afsanazamannipa7711 3 жыл бұрын
A big thumbs up for the clean demonstration of how the POST method works. Thanks.
@arupsharma2792
@arupsharma2792 Жыл бұрын
I am new to programming and learning Java Script....this is what exactly i was looking for.....Thanks!!!
@andresacosta9824
@andresacosta9824 3 жыл бұрын
From Colombia to you let me tell you something...you Sir got my respects, not everybody knows how to explain this by walking through every detail so everybody becomes aware of how things fall into place the way you did...suscribed!!PD u r truly gifted btw keep it up
@rickvazquez6578
@rickvazquez6578 4 жыл бұрын
MATE! this tutorial is the bomb! I love how you actually walked through documentation! Thanks soo much!
@codyfisher9972
@codyfisher9972 2 жыл бұрын
looked in a lot of places to try and get this explained and you by far have done it the best thank you
@EliZevin
@EliZevin 2 жыл бұрын
thanks, i forgot how to do with without React and you saved my day
@dfrecipes1138
@dfrecipes1138 3 жыл бұрын
What a great tutorial... I've done a lot of middleware and backend stuff. but the front-end just confuses me. Just starting to figure out API calls. and this was such a great help... I copied everything as you spoke about it (had to pause a few times), and everything worked!!!!, so many other youTubers out there, and their code for some reason or another, just doesn't work. -- Yours worked great and really helped me. THANKS!!!
@fluntimes
@fluntimes 3 жыл бұрын
A tutorial that doesn't leave the viewer with console.log(data). You figured out people actually want to do things with the data!
@sksahilhossen8527
@sksahilhossen8527 3 жыл бұрын
oh dyr u r the savior.. i was doing console.log(data) and then data.forEach(e) and it ruins my whole day.. now i understand its console.log(data.data) and for iterating the array elements its data.data.forEach(e). thanks.. GOD bless you.
@zohrarazaq8244
@zohrarazaq8244 4 жыл бұрын
THIS WAS AMAZING!!!! thanks so much for doing the tutorial in incremental stages and then displaying what happens on the HTML
@drzacks
@drzacks 4 жыл бұрын
Really helpful for me beginner. It really confusing if I just looking at finished codes but with your step by step coaching how you built it up, everything makes sense. Thank you for amazing tutorial!!
@MystmaxkinnTV
@MystmaxkinnTV 2 жыл бұрын
This is exactly what I was looking for good Sir. Thank you.
@SahraClayton
@SahraClayton 4 жыл бұрын
So glad I found this tutorial. As a beginner this was really helpful.
@enriquesalomon8197
@enriquesalomon8197 4 жыл бұрын
Thanks for this video sir . You help me with my problem 😉. This is exactly what I am looking for 🙏
@Landuytfamily
@Landuytfamily 3 жыл бұрын
I cannot express how much grateful I feel watching this tutorial. Super Precious!! Liked and subscribed. Please send me a link to learn async and await version. THANK YOU
@spartanpenguin3351
@spartanpenguin3351 3 жыл бұрын
I love how you explain everything clearly, thank you! I subscribe, please continue sharing us your knowledge
@Chickin
@Chickin 2 жыл бұрын
ty dude
@Warpgatez
@Warpgatez 3 жыл бұрын
“Whoopsiiieeesss” 😂😂😂 great video. Never seen your content before but if they’re all like this then you have a great channel
@jamblob3208
@jamblob3208 11 күн бұрын
fascinating. First step, step back.
@Robcabobb
@Robcabobb 2 жыл бұрын
Love this super easy to follow. Thank you!
@gayanegrigoryan9565
@gayanegrigoryan9565 2 жыл бұрын
Great thanks, it was so helpful for my task!!!🤩🤩🤩
@balajitech5263
@balajitech5263 3 жыл бұрын
This is so useful man,plz post more video
@mohammedh4844
@mohammedh4844 2 жыл бұрын
Excellent tutorial. Continue with more tutorial
@MsRitika1990
@MsRitika1990 3 жыл бұрын
Please use axios async await...you don't have to use then again and again...looks neat too.. Video is too good..this is what I was looking for...
@parsamarami5683
@parsamarami5683 Жыл бұрын
thanks bro...useful ;)
@neets7519
@neets7519 2 жыл бұрын
Awesome tutorial 🧡 from Australia!
@ioslearner9536
@ioslearner9536 3 жыл бұрын
Thank you so much sir... This video really helped me a lot. I am subscribing to your channel right now...
@thayrangabriel2087
@thayrangabriel2087 3 жыл бұрын
Thanks so much for making this tuutorial!
@sandeepkumarmahto5428
@sandeepkumarmahto5428 4 жыл бұрын
Thanks sir I look for the exactly this solution..
@nonodev
@nonodev 3 жыл бұрын
That Tutorial is Gold. Thanks
@basement_grower
@basement_grower 2 жыл бұрын
Nice video man, helped me out
@sahil-ld1bu
@sahil-ld1bu 2 жыл бұрын
please make more tutorials on javaScript it will very helpful
@itshamiiid
@itshamiiid 2 жыл бұрын
thanks. this was helpful.
@KANCHANADHIKRAOJADHAV
@KANCHANADHIKRAOJADHAV Жыл бұрын
Thanks alot sir!
@athraafaraj8387
@athraafaraj8387 2 жыл бұрын
thank you very useful
@user-mishapagan
@user-mishapagan 3 жыл бұрын
thank you so much , it was a REAL help!! )
@cantareiramartins55
@cantareiramartins55 3 жыл бұрын
Thank you for the explanation!
@verdynandreyhans9592
@verdynandreyhans9592 2 жыл бұрын
you saved my day broh ....
@amirhoxha6231
@amirhoxha6231 2 жыл бұрын
Amazing video
@justcats2184
@justcats2184 3 жыл бұрын
I love how u explain please make more tutorial videoss
@adityaband6919
@adityaband6919 3 жыл бұрын
Really nice video
@cuadros9870
@cuadros9870 3 жыл бұрын
I actually passed an interview after watching this video
@chigozieemeafu4415
@chigozieemeafu4415 2 жыл бұрын
it was an awesome lesson made easy.
@Lyrik-Klinge
@Lyrik-Klinge 2 жыл бұрын
Thanks!
@HemmingEducation
@HemmingEducation 2 жыл бұрын
Great!
@RocoSafreti
@RocoSafreti 10 ай бұрын
👌
@Smart.Potato
@Smart.Potato 3 жыл бұрын
7:44 I am getting Name: ${user.first_name}Name: ${user.first_name}Name: ${user.first_name}Name: ${user.first_name}Name: ${user.first_name} instead of actual names in API, I double checked and everything is the same as you typed. not sure what I'm doing wrong. could you help please.
@matusbalogh7778
@matusbalogh7778 2 жыл бұрын
This video is fantastic, exactly what I was looking for! Thank you! One question - I'm trying to only display the first result (in your example it's Name: George) but can't seem to be able to filter it out. I can't tell where I'm going wrong. Could you please advise on how to approach this? I'm sure it must be quite simple.
@hikari1690
@hikari1690 2 жыл бұрын
Depending on the api, you may be able to add a query to return only one. Alternatively, understanding the returned object can allow you to manipulate it. For example, if it's an array you can just use index 0 to get the first item. I didnt finish watching the video cause it's too dry so I dont know what this api returns... But it's a month since your comment so I'm guessing you already got an answer by now anyways 😂
@AD-lr6pc
@AD-lr6pc 3 жыл бұрын
Wow great tutorial 👍
@hchchc948
@hchchc948 4 жыл бұрын
How would you go about instantiating a new instance of a class with the properties of the fetched data? Awesome tutorial btw!
@owltrades
@owltrades 2 жыл бұрын
Thanks man
@Jakobowsky
@Jakobowsky 4 жыл бұрын
Thanks a lot for this video!
@fridalundstrom6212
@fridalundstrom6212 4 жыл бұрын
Great video! Do you have any suggestions on how to put the data into 3 separate divs that I allready have created in my HTML? The API I have contains three arrays, and I want to put each array in separate divs by using Javascript.
@codebushi
@codebushi 4 жыл бұрын
You probably need to split up the arrays and do a .map() three different times in each of your separate divs.
@mariejolie2645
@mariejolie2645 2 жыл бұрын
I would love to know how to get a user by id in the url and display its infos by clicking on its avatar for instance. Any tutorial on this ? thanks
@adminyork4397
@adminyork4397 3 жыл бұрын
Can you make a video on how to create a pop-out modal when any of these users are selected and provide additional info about them in the modal? Also on your then method could you just do .them(data => console.log(data.data)) making it a one liner instead of 3? Thx for the video!
@NelIglesiasPerez
@NelIglesiasPerez 4 жыл бұрын
THANK YOU
@user-mishapagan
@user-mishapagan 3 жыл бұрын
I have a question . If you had to display an average value for each user. How would you implement that into template literal? Is that even possible? I'm trying to accomplishe that atm and totally stuck :(
@MehediHasanMondal
@MehediHasanMondal 4 жыл бұрын
Nice tutorial buddy
@codebushi
@codebushi 4 жыл бұрын
Thank you!
@ltmanbonzo7762
@ltmanbonzo7762 2 жыл бұрын
Can someone please tell me why it is not outputting on the html correctly for me? For example it is only outputting "Name: ${user.first_name}", instead of "Name: George"
@ritsk4338
@ritsk4338 4 жыл бұрын
Awesome video.
@Asif78611
@Asif78611 3 жыл бұрын
What if we want return an integer value in the string literal. I tried but its showing undefined. Please help
@ovidiublaga1
@ovidiublaga1 3 жыл бұрын
Hello. Have you though about doing the pagination?
@egel2787
@egel2787 2 жыл бұрын
How can I display only the first id1 of database
@pauloh.2503
@pauloh.2503 3 жыл бұрын
nice
@IneyeGabriel
@IneyeGabriel 4 жыл бұрын
How do we select the first child and add a class to it?
@NuwanThisara
@NuwanThisara 4 жыл бұрын
Hello, thanks for the tutorial, but console says --- TypeError: data.data.map is not a function -- then what?
@codebushi
@codebushi 4 жыл бұрын
Hi! Can you share your code maybe with jsfiddle.net? Make sure you 'return' something in your first '.then()' and do a console.log of data first to see what the value is.
@Univelz
@Univelz Жыл бұрын
i receive error : TypeError: Cannot read properties of null (reading 'insertAdjacentHTML') message: 'Cannot read properties of null (reading 'insertAdjacentHTML')'} Why this happen even though i follow the tutorial?
@codebushi
@codebushi Жыл бұрын
If you can share your code, I can take a look!
@Univelz
@Univelz Жыл бұрын
@@codebushi my apprenticeship already end month ago and it solved already so yeah. Altho i dont remember the problem anymore
@muhammadaqilal-muhtadi9185
@muhammadaqilal-muhtadi9185 4 жыл бұрын
how to connect my fetch API code with other code ? so i can rendering data with the other code *i'm sorry if my language is so bad 🙏
@Faisal-jo5vk
@Faisal-jo5vk 2 жыл бұрын
what if i am not fetching a json file
@Smart.Potato
@Smart.Potato 3 жыл бұрын
return 'Name: ${user.first_name} '; my VSCode is thinking this line as a whole string and does not understand ${} is JS. what do I do please Edit: ok I finally figured it out. I was trying ' instead of ` holy cow
@r7butler
@r7butler 4 жыл бұрын
Gotta love how Emma Wong turned out to be a white man seemingly in his late 20's
@maliknauman7873
@maliknauman7873 3 жыл бұрын
how can we post image
@ritsk4338
@ritsk4338 4 жыл бұрын
please create a video on promise
@engr.kingsleyfoncham2619
@engr.kingsleyfoncham2619 2 жыл бұрын
im having some issues
@codebushi
@codebushi 2 жыл бұрын
Hi! What issues are you having?
@alexmelka5324
@alexmelka5324 4 жыл бұрын
is it fucking so hard to make it at readable size ??
@tamang1234
@tamang1234 4 жыл бұрын
why are u so handsome
@negrocomdentebranco
@negrocomdentebranco 2 жыл бұрын
hello its possible to delete from a public API?
1.1: fetch() - Working With Data & APIs in JavaScript
15:39
The Coding Train
Рет қаралды 454 М.
React.memo, useMemo, and useCallback Optimizations
22:09
Code Bushi
Рет қаралды 44 М.
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 29 МЛН
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 127 МЛН
Кәсіпқой бокс | Жәнібек Әлімханұлы - Андрей Михайлович
48:57
How to display data from an API using Vanilla Javascript
14:03
Web Dev Cody
Рет қаралды 17 М.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 136 М.
Fetch API Explained - Working with Data & APIs in JavaScript
18:59
DOM API - JavaScript Tutorial for beginners
42:17
ColorCode
Рет қаралды 35 М.
Ten Steps to Mastering the Fetch API
2:19:52
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 46 М.
1.4: JSON - Working with Data and APIs in JavaScript
16:22
The Coding Train
Рет қаралды 645 М.
Callbacks, Promises, Async Await | JavaScript Fetch API Explained
1:05:05
JavaScript Fetch API - One Mistake I ALWAYS MAKE!
4:47
James Q Quick
Рет қаралды 32 М.