Response Body Methods
Response provides multiple body-reading methods. Each can only be called once — clone() if you need to read twice.
Response provides multiple body-reading methods. Each can only be called once — clone() if you need to read twice.
const res = await fetch("/api/data");
// Choose one:
const json = await res.json(); // parse JSON
const text = await res.text(); // raw string
const blob = await res.blob(); // binary file
const ab = await res.arrayBuffer(); // raw bytes
const form = await res.formData(); // form fields
// Clone to read twice
const clone = res.clone();
const [json2, text2] = await Promise.all([res.json(), clone.text()]);
Response bodies are streams — once consumed they are gone. Use .clone() before reading twice.
More in JavaScript