Fetch API & Handling JSON Responses
What best practice does this code demonstrate?
const response = await fetch('/api/data');
const contentType = response.headers.get('content-type');
let data;
if (contentType?.includes('application/json')) {
data = await response.json();
} else if (contentType?.includes('text/')) {
data = await response.text();
} else if (contentType?.includes('image/')) {
data = await response.blob();
}