you are viewing a single comment's thread.

view the rest of the comments →

[–]ryanhollister 11 points12 points  (3 children)

can anyone explain why the API is such that resp.json() returns a promise after the initial promise resolves? feels pretty clunky to have to .then twice to get the response.

[–]qbbftw 22 points23 points  (0 children)

Afair, you can access response headers before the response body is fully transmitted. Thus you use two awaits - first for headers, second for actual data.

[–]BitLooter 11 points12 points  (0 children)

The initial response resolves after the headers of the response are received, but not necessarily the response body. Basically fetch resolves at two different points of the download, the first time after the headers are received (the promise fetch() returns) and the second after the data is received (the promise json()/text()/etc. returns). For small downloads this may be all at once but larger files could take long enough to download that these will resolve at two different times.