Is it possible to make an API call using axios based on the response of another initial API call, all within asynchronous functions?
I attempted the following approach with await/promise:
function fetchUserDetails(userId) {
return axios.get( "https://apicall/" + userId )
}
function fetchUserPosts(username) {
return axios.get("https://apicall/" + username)
}
var UsersOutput = async function () {
const userDetails = await fetchUserDetails(2928928);
const userPosts = await fetchUserPosts(userDetails.data.username);
return { userDetails, userPosts }
}
However, this doesn't seem to return any data from either of the calls. Any advice would be greatly appreciated.