Fetch API & Rendering Data with JavaScript

preview_player
Показать описание
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:
Рекомендации по теме
Комментарии
Автор

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.

OverwhelmingGrace
Автор

MATE! this tutorial is the bomb! I love how you actually walked through documentation! Thanks soo much!

rickvazquez
Автор

I'm gonna cry, I have seen the light. Bless your soul, kind man.

guchi
Автор

A big thumbs up for the clean demonstration of how the POST method works. Thanks.

afsanazamannipa
Автор

GOAT! This guy explains everything better than any Udemy instructor

drrjgtb
Автор

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

andresacosta
Автор

THIS WAS AMAZING!!!! thanks so much for doing the tutorial in incremental stages and then displaying what happens on the HTML

zohrarazaq
Автор

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!!!

dfrecipes
Автор

I am new to programming and learning Java Script....this is what exactly i was looking

arupsharma
Автор

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!!

drzacks
Автор

A tutorial that doesn't leave the viewer with console.log(data). You figured out people actually want to do things with the data!

fluntimes
Автор

looked in a lot of places to try and get this explained and you by far have done it the best thank you

codyfisher
Автор

thanks, i forgot how to do with without React and you saved my day

EliZevin
Автор

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.

sksahilhossen
Автор

This is exactly what I was looking for good Sir.
Thank you.

MystmaxkinnTV
Автор

So glad I found this tutorial. As a beginner this was really helpful.

SahraClayton
Автор

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

Landuytfamily
Автор

Thanks for this video sir . You help me with my problem 😉. This is exactly what I am looking for 🙏

enriquesalomon
Автор

Excellent tutorial. Continue with more tutorial

mohammedh
Автор

“Whoopsiiieeesss” 😂😂😂 great video. Never seen your content before but if they’re all like this then you have a great channel

Warpgatez