Efficient ES6 async await with fetch

  Рет қаралды 15,482

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

4 жыл бұрын

This video explains how to effectively combine async await functions with fetch and include proper error handling.
Code GIST: gist.github.com/prof3ssorSt3v...

Пікірлер: 50
@mimishiba
@mimishiba 3 жыл бұрын
Wow that's a really neat way of error handling that no other channels have explained before! Definitely learned something valuable here. Thanks!
@mohamedkhodary7831
@mohamedkhodary7831 4 жыл бұрын
Your Channel is like gold mining Steve, thank you for this fantastic explanation and the pure content you delivered , keep it up.
@gospodarsile4606
@gospodarsile4606 4 жыл бұрын
Your videos are extremely well explained and contain quality content. However, your channel still doesn't have the number of views and followers it deserves to have. With this comment, first of all, I want to thank you for the knowledge you share with us and I also want to suggest an example of how to get more followers and viewers. I recommend that you create a bigger project, a realistic project that young developers face. May be divided into several small sections and unite to a playlist, or record it in its entirety for a couple of hours. An example project would be a CRUD application with ECMAScript 6+ standard. I hope that you will do something like that for your viewers. Have a nice day :)
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Eventually I will create full courses. It has been my intention for a long time to do that either on here or Udemy or SkillShare or BitDegree or some other place. I have been approached by several online schools to create courses. It's just a matter having the time. These videos I can do in a day as I have the time. Full courses take a long time to plan, develop, record and edit. I do these videos in my spare time on top of my full-time job.
@tedfitzpatrickyt
@tedfitzpatrickyt 4 жыл бұрын
A MERN-stack PWA using oAuth and deployed using Docker. Just cause I’m learning how to do this ;-) Thanks Steve
@roshinimala3759
@roshinimala3759 2 жыл бұрын
Thanks a lot Prof 😄Today I learnt something new
@quaternion-pi
@quaternion-pi 4 жыл бұрын
Fantastic content! (as always I learned new, useful techniques). Thanks for all your teaching.
@PIRAKAS666
@PIRAKAS666 2 жыл бұрын
Great as always.
@MrSalFav
@MrSalFav 2 жыл бұрын
Thank you !! Really well explained and calm to watch and straight to the point. I watched alot of your vids and they are all really well made.
@MoDeadYT
@MoDeadYT 3 жыл бұрын
Today is a great day! It is the first day I have ever clicked the notification bell. haha
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Thanks! :)
@FranciscoJunior29
@FranciscoJunior29 4 жыл бұрын
Another great class. Excellent job.
@iwswordpress
@iwswordpress 4 жыл бұрын
Very good example, well explained.
@geraldmartinez3865
@geraldmartinez3865 4 жыл бұрын
Thanks a lot Steve. Good tutorial
@mahmoudmiz3531
@mahmoudmiz3531 4 жыл бұрын
Great explanation, thank you!
@maspoetry1
@maspoetry1 3 жыл бұрын
nice to see this channel getting big. i don't know a better teaching style
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
I appreciate that!
@se7en2021
@se7en2021 3 жыл бұрын
Love your channel
@giandomenicoriceputi6275
@giandomenicoriceputi6275 3 жыл бұрын
If want understand something I heve to follow your videos
@kirillbaryba746
@kirillbaryba746 4 жыл бұрын
Thanks, What I need!
@MoDeadYT
@MoDeadYT 3 жыл бұрын
Thank you so so so so much!
@TheRegalboss
@TheRegalboss 3 жыл бұрын
Excellent!
@olubisidavid7864
@olubisidavid7864 4 жыл бұрын
document.write("Thanks alot sir...these are awesome contents');
@sabuein
@sabuein Жыл бұрын
Thank you.
@tezzarida
@tezzarida 4 жыл бұрын
Thank you for the video! Can you please say which microphone do you use?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Blue yeti USB mic
@iliashterev38
@iliashterev38 2 жыл бұрын
Greetings from Bulgaria. Thank you (perhaps 5ht time in different comments) for your time and efforts to put those so valuable tutorials. One question please, if you have time - what about the regular try catch blocks inside the async funct. Are they not applicable here or this is just more appropriate (or should I say professional) way of coding ??
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
You can use the standard .then() method with catch() or try catch with await or a combination. As long as you understand how the different ways work feel free to use any approach.
@chikaodili
@chikaodili 4 жыл бұрын
Thanks Steve! One question though; is it possible to return the data from function f in your example instead of logging it to console ? Trying to return "data" still returned a promised. Is there a way around this ?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
response.json() returns a promise. We can add the then( ) method to data to get at the actual data.
@chikaodili
@chikaodili 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Many thanks
@ironmanlifts
@ironmanlifts 4 жыл бұрын
Thanks , await makes more sense now. What if you just wrap everything inside the async function with try {}catch{} ? Would that work the same as the handleErr function ?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
You can put a try catch block around it but I prefer to use the catch( ) method that comes with Promises.
@RajveerSingh-yb6zq
@RajveerSingh-yb6zq 3 жыл бұрын
Great. One Question though. In the End, Why data.code && data.code == 400 ???????
@RajveerSingh-yb6zq
@RajveerSingh-yb6zq 3 жыл бұрын
got it. First data.code check the code property availibity in the data obj.
@dawidpomioto1595
@dawidpomioto1595 4 жыл бұрын
What about using try catch block instead of crating handleErorr function?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
You can but then you are mixing the sync and async approaches. Just feels mismatched and inappropriate to me.
@misterl8129
@misterl8129 4 жыл бұрын
when we need to use asyn fetch vs a regular fetch??
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
You, as the developer, get to choose. They are two solutions that are equal and solve the same problem. What is your preference in coding...
@carbonio14
@carbonio14 3 жыл бұрын
I need to extract a price from an cryptocurrency exchange url address. Using a fetch request and getting a json response (crypto symbol and price) how can I take advantage using async/await? I need only the price data. thanks
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Using or not using async / await has zero impact on how you get to specific values in the data. With it, like I show in the video, you are passing the value back from the fetch().then().then( ) to a variable. Without it you just use the data inside the second then( ) function.
@evilwarrior4095
@evilwarrior4095 4 жыл бұрын
why did you use two data.code inside if statement. im really new to this concept. please help me
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
The first one checks for the existence of a property called code inside the data object. The second checks for the value of that property. kzbin.info/www/bejne/hX27qqSrqrJja7M
@evilwarrior4095
@evilwarrior4095 4 жыл бұрын
Steve Griffith thank you very much sir . i was so consumed with this async stuff that i literally forgot and didn't pay attention to the basics 😅. im dumbfounded right now. thanks to your tutorial im on the clear now .
@RajveerSingh-yb6zq
@RajveerSingh-yb6zq 3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 that we could have avoided with data?.code instead of data.code right?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
@@RajveerSingh-yb6zq yes. But optional chaining still has limited support. It is still fairly new.
@adilismail3593
@adilismail3593 4 жыл бұрын
Messy code
Why Should I Use const in JavaScript
9:04
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
Promises in JavaScript (+ Async Await, Fetch API Example)
24:02
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 28 МЛН
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 192 МЛН
Combining Async Await with Promises
9:10
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 7 М.
ES6 Iterator & Generator Fundamentals
18:18
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 31 М.
Using FormData Objects Effectively
13:14
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 36 М.
Tips For Using Async/Await in JavaScript
16:26
James Q Quick
Рет қаралды 395 М.
JavaScript Fetch with Request and Headers Objects
16:26
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 64 М.
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 383 М.
Object Oriented vs Functional Programming with TypeScript
12:07
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 28 МЛН