I currently have my own api i am trying to send and retrieve data from.
In the api I am trying to send an object to the front-end using something like res.send({data: 1})
.
I am easily able to access this data using postman but when trying to fetch the data using - well - fetch, i have no way to acess it. the way I try to fetch it is as follows:
const response = await fetch("http://localhost:2000/user/login", {
method: "post",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(user),
});
And logged response
looks like this:
body: (...)
bodyUsed: false
headers: Headers
[[Prototype]]: Headers
ok: true
redirected: false
status: 200
type: "cors"
url: "http://localhost:2000/user/login"
[[Prototype]]: Response
The {data: 1}
object is nowhere to be found and i have no clue how to access it.
Is this the wrong way to go about retrieving and sending data from and to an api or am i just overlooking something? What would the best way to transfer data like this be then?
Thanks in advance!
Ps: the {data: 1}
is just an example and the real way i would use this at the moment would be to fetch data from an express session cookie.