I've looked at various webpages, including this stack overflow question: How to get data from observable in angular2
All of the information says that I need to subscribe to the Observable and then do something with the data within the next function, which is exactly what I'm doing. But what gets logged to the console isn't the body of the request, it seems to be something else that looks like this.
Response {type: "cors", url: "https://reqres.in/api/users?page=1", redirected: false, status: 200, ok: true, …}
body: ReadableStream
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: ""
type: "cors"
url: "https://reqres.in/api/users?page=1"
__proto__: Response
I can get the body of the Observable by using body()
but this just returns a ReadableStream
object and not the JSON string I'm expecting?
Here is my code.
const data = from(fetch('https://reqres.in/api/users?page=1'));
data.subscribe({
next(response) {
console.log(response);
},
error(err) { console.error('Error: ' + err); },
complete() { console.log('Completed'); }
});
What do I need to do to get the JSON string that is found at the endpoint specified so I can actually do something with it. Do I need to map the stream to an object or something?