So i have a fetch function that should return me a url from a api that i created. It kinda works, but the issue is instead of returning the URL it returns promise pending. I’ve used async-await so I don’t know what could be causing the issue
const getUser = async (id) => {
let url = `http://127.0.0.1:8000/api/user/${id}/`
const response = await fetch(url)
const data = await response.json()
return data.avatar
}
console.log(getUser(1))
This is the response from the API
{
"id": 1,
"email": "[email protected]",
"username": "somewhattastydonut",
"avatar": "https://somebucketname.s3.amazonaws.com/default.jpg"
}
I want it to return just the URL from the avatar but i don’t know what I’m doing wrong for it to return promise pending