Skip to content
Advertisement

Getting Text From Fetch Response Object

I’m using fetch to make API calls and everything works but in this particular instance I’m running into an issue because the API simply returns a string — not an object.

Typically, the API returns an object and I can parse the JSON object and get what I want but in this case, I’m having trouble finding the text I’m getting from the API in the response object.

Here’s what the response object looks like. enter image description here

I thought I’d find the text inside the body but I can’t seem to find it. Where do I look?

Advertisement

Answer

Using the fetch JavaScript API you can try:

response.text().then(function (text) {
  // do something with the text response 
});

Also take a look at the docs on fetch > response > body interface methods

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement