JavaScript Request vs Response Object Differences

In modern JavaScript, the Fetch API provides standardized Request and Response interfaces to handle HTTP communication across browsers, Service Workers, and server-side runtimes like Node.js and Deno. This article breaks down the fundamental differences between these two objects, detailing their unique properties, methods, and specific roles in the client-server lifecycle.

The Fundamental Difference

The core distinction lies in the direction of data flow and the HTTP semantics each object represents:


The Request Object

A Request object encapsulates all the parameters required to perform an HTTP call. While you often pass a URL and an options object directly to fetch(), instantiating a new Request() allows you to create reusable, pre-configured request templates.

Key Properties:

Example Usage:

const request = new Request('https://api.example.com/data', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Alice' })
});

fetch(request);

The Response Object

A Response object represents the result returned by an HTTP operation. It is generated automatically when a fetch() promise resolves, but can also be manually instantiated in server environments or Service Workers to return data to a client.

Key Properties:

Example Usage:

const response = await fetch('https://api.example.com/data');

if (response.ok) {
  const data = await response.json();
  console.log(data);
} else {
  console.error(`HTTP Error: ${response.status} ${response.statusText}`);
}

Comparison Summary

Feature Request Object Response Object
Primary Role Describes an outgoing request to a resource. Describes the incoming result of a request.
Identifying State Defined by method (GET, POST, etc.) and url. Defined by status (200, 404, etc.) and ok.
Security Attributes Contains mode, credentials, integrity. Contains type (e.g., cors, opaque), redirected.
Typical Origin Created by client applications or received in server handlers. Created by servers/workers or received via fetch().

Shared Characteristics: The Body Mixin

Despite their differences, both Request and Response implement the Body interface. This means both objects handle streaming payloads similarly and provide identical methods to read and parse data:

Because the body is a readable stream, it can only be read once by either object unless cloned using the .clone() method.