I'm using fetch()
for the first time to get some data from the API: 'https://www.codewars.com/api/v1/users/thenarfer'.
My goal is to console.log
the data. I believe the data to be in JSON format.
The error I get with the following code is:
Uncaught ReferenceError: data is not defined
Is POST or GET the correct approach? How do I continue from here?
fetch('https://www.codewars.com/api/v1/users/thenarfer', {
method: 'GET',
mode: 'no-cors',
credentials: 'include',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
}).then((res) => res.json())
.then((data) => {
console.log(data)
})
.catch((err) => console.log(err));