Showing posts with label await. Show all posts
Showing posts with label await. Show all posts

Tuesday, September 7, 2021

Async Await Simple example


let url1 = "https://reqres.in/api/users";
async function users() {
    let response = await fetch(url1);
    let user = await response.json();
    return user;

};

let singleUrl = "https://reqres.in/api/users/";
async function userData(data) {
    let url = singleUrl + data;
    let response = await fetch(url);
    let user = await response.json();
    return user;
};


users().then(respData => {
    console.log(respData.data);
    var userid = respData.data[0]['id']
    userData(userid).then((responseData=> {
        console.log(responseData);
    });
});