SyntaxStudy
Sign Up
JavaScript Reading Response Bodies
JavaScript Beginner 3 min read

Reading Response Bodies

Response Body Methods

Response provides multiple body-reading methods. Each can only be called once — clone() if you need to read twice.

Example
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()]);
Pro Tip

Response bodies are streams — once consumed they are gone. Use .clone() before reading twice.