The Response Object Structure
You'll learn: How to inspect and use the key properties of the Response object returned by fetch() to understand what the server sent back.
What Is the Response Object?
When fetch() completes, it resolves to a Response object—a structured container holding everything the server returned. Think of it like opening a package: before you unpack the contents (the body), you can inspect the shipping label and receipt (the metadata).
The Response object provides five essential properties for examining HTTP responses:
Core Response Properties
status — The numeric HTTP status code (e.g., 200, 404, 500). This tells you the outcome category: success (2xx), redirection (3xx), client error (4xx), or server error (5xx).
statusText — A human-readable phrase matching the status code (e.g., "OK", "Not Found"). While descriptive, it's less reliable than status since servers can customize it.
ok — A boolean shortcut: true if status is in the range 200–299, false otherwise. Perfect for quick success checks without memorizing status codes.
headers — A Headers object containing all response headers. Use methods like get('content-type') to inspect server-provided metadata about caching, content types, or authentication tokens.
type — Describes the response type: "basic" (same-origin), "cors" (cross-origin with CORS), "opaque" (no-cors mode), or "error" (network failure). This helps understand what CORS restrictions apply.
Inspecting Before Reading
These properties are available immediately—before you call json() or text() to read the body. This lets you validate responses first, handling errors gracefully without wasting time parsing invalid data.
Key Takeaway: The Response object's status, statusText, ok, headers, and type properties give you complete visibility into HTTP response metadata, enabling robust error handling and conditional logic before processing response bodies.