Async/Await Javascript and Promises - Fetch API vs Axios by Example

preview_player
Показать описание
In this video, I will show you how to use the Async - Await syntax in your Javascript code. This syntax makes your asynchronous code looks like synchronous code and one of the most common cases to use asynchronous code is when we want to fetch data from an external API. Most libraries use promises like for example Axios and the Fetch API so we will see some examples using those APIs.

0:00 - What is the Async/Await syntax
0:29 - Create initial demo html/js
2:03 - What is a Promise object
6:47 - Promises and Fetch API
11:29 - Use Axios to fetch data
14:01 - Async/Await syntax using Axios
17:02 - How to handle multiple Promises at the same time
19:21 - How to handle errors with the Async/Await syntax

#javascript #async #axios
Рекомендации по теме
Комментарии
Автор

Totally unrelated but all this .then() calls made me remember this old movie joke (and then? and theeeen?):


Have you watched that movie? or I'm just too old :)

CarlosMafla
Автор

Great content Carlos but how can I save what I fetch via axios in a variable? I need to save it so i can pass it to D3 and make a graph. If I try to save it, what I get is a Promise and I need an array of Jsons. Thanks.

jbwnknb
Автор

Dude, amazing video, but you should consider educate your voice to avoid monotone voice, cheers

moiseslezama
Автор

how did you intserted html by typing html5, can i do this in vs code?

ashwani
Автор

Why to use async await if there is a promise using in axios, and what about to create instaces class en a api axios

patricializarazo
Автор

Can you share your vimrc config, love your theme

muhammadhoollick
Автор

Whats the difference between this:
const posts = await axios(response.data); and this:
const posts = await(response.data); ?
The proper way is to use the axios keyword? cause it works even if I dont use it. By the way, great video, thanks!
Here is my complete example code:
const getPostsAsync = async(url) => {
const response = await axios(url)
console.log(response);
const posts = await axios(response.data);
// const posts = await(response.data);
console.log(posts);
}
getPostsAsync(url);

miguelnoriega
Автор

why dont use async utility library with axios? : )

Microphunktv-jbkj