Hello. First .then is resolved and have a value response. Why if i log res.text it is just a promise, and when i make another then with the same return , next .then with the same res.text it's a string now?? May someone explain it for me:)?
-
short answer is - this is how `fetch` is specified and implemented - so, the reason you have to "make another .then" is because that's how you use fetch API – Jaromanda X Mar 27 '19 at 23:22
-
Possible duplicate of [Why does .json() return a promise?](https://stackoverflow.com/questions/37555031/why-does-json-return-a-promise) – sideshowbarker Mar 28 '19 at 01:14
2 Answers
The fetch
function returns a Promise that resolves with a Body
response.
Paraphrased from Mozilla: Fetch and Mozilla: Body:
The fetch() method... returns a Promise that resolves to the Response to that request, whether it is successful or not... Once a Response is retrieved, there are a number of methods available to define what the body content is and how it should be handled.
If you then navigate to the documentation for Body
you can see that it has a number of methods on it. The Body.text()
method:
Takes a Response stream and reads it to completion. It returns a promise that resolves with a USVString (text). The response is always decoded using UTF-8.
The behavior you've described is how the fetch
API is expected to behave.

- 5,950
- 5
- 29
- 44
The Fetch API returns a promise which resolves to a Response. The Response itself has a text() method which returns a promise as well. You can use this method to read the Response-Stream as a text. See https://developer.mozilla.org/en-US/docs/Web/API/Response

- 816
- 9
- 24