I\'m trying something simple where I make a request from the front end of my app using the fetch API like so
let request = new Request(\'http://localhost:3000/a
Okay, this works on my front end
fetch(request).then((response) => {
console.log(response);
response.json().then((data) => {
console.log(data);
});
});
The key part was the resolution of the promise chain.
Similar question here JavaScript fetch API - Why does response.json() return a promise object (instead of JSON)?
Could also split in to two like this
async fetchData() {
let config = {
headers: {
'Accept': 'application/json' //or text/json
}
}
fetch(http://localhost:3000/add`, config)
.then(res => {
return res.json();
}).then(this.setResults);
//setResults
setResults(results) {
this.details = results;
//or: let details = results
console.log(details) (or: this.details)