Response Types in JavaScript

From the Fetch API cheat sheet · Response Handling · verified Jul 2026

Response Types

Parsing different response formats and handling content types

javascript
// JSON response
const response = await fetch('/api/data')
const json = await response.json()

// Text response
const response = await fetch('/api/text')
const text = await response.text()

// Blob (binary data)
const response = await fetch('/api/image')
const blob = await response.blob()
const url = URL.createObjectURL(blob)

// FormData
const response = await fetch('/api/form')
const formData = await response.formData()

// ArrayBuffer
const response = await fetch('/api/binary')
const buffer = await response.arrayBuffer()

// Clone response (read body twice)
const response = await fetch('/api/data')
const clone = response.clone()

const json = await response.json()
const text = await clone.text()
🟢 Response body can only be read once - clone if needed
💡 Check content-type header to determine parsing method
⚡ Use streams for large files to avoid memory issues
📌 Always revoke object URLs to prevent memory leaks

More JavaScript tasks

Back to the full Fetch API cheat sheet