How to know the type of the response in Fetch API?
In XMLHttpRequest, there’s the responseType
property which indicates the type of the returned response’s body (json, text, blob, etc.). While in the Fetch API response, even though there are useful methods to parse its body (json()
, text()
, blob()
, etc.), I still didn’t find any property like the XMLHttpRequest’s responseType
property, to indicate what’s the type of the response.
Advertisement
Answer
I think you can check the headers of the response for the content-type as below:
response.headers.get("content-type")