Home > Article > Web Front-end > Why `response.json()` must be awaited
Credit to the source, I'm just putting it in writing for easier access!
It turns out json() must be awaited because fetch() will resolve or reject when it receives the response headers, regardless of what the body is! The body is likely to be much larger in size, and may even take a long time to arrive and/or might do so in chunks, thus it has to be awaited even after fetch() has finished.
I had no idea why this behaviour existed until now. I love learning deeper stuff like this, and hope you do too!
Again, watch the video for a better and more visual explanation! (it's 6 minutes long, worth every second)
The above is the detailed content of Why `response.json()` must be awaited. For more information, please follow other related articles on the PHP Chinese website!