app.js
const axios = require('axios') try { console.log("start"); function getUserName() { return axios.get('http://localhost:3000/heroes'); } function getId() { return axios.get('http://localhost:3000/heroes'); } // Performing multiple concurrent requests waiting time 4 seconds axios.all([getUserName(), getId()]) .then(axios.spread(function (acct, perms) { const user = acct.data[0].param; const id = perms.data[1].param; console.log(`${user} ${id}`) const str = 'https://jsonplaceholder.typicode.com/' + user + '/' + id console.log(str) axios.get(str).then(response => console.log(response.data.name)); })); } catch (error) { console.error(error); }
No comments:
Post a Comment