So when we give this function getApiData something to fetch, we want it to actually return the fetched data. At the moment it returns "undefined" and we don't understand why.
console.log(name)
if (`${restVar}` != `GET`) {
bodyData = JSON.stringify(bodyData);
}
fetch(`${url}`, {
method: `${restVar}`,
headers: {
'Content-Type': 'application/json'
},
body: bodyData
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
return data;
})
.catch((error) => {
console.error('Error:', error)
});
}```
Any help would be much appreciated :)