JavaScript Request basics

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Use new Request(input, init) to build a reusable request. Pass it to fetch(request).

JavaScript Syntax

JavaScript
const req = new Request("https://example.com", {
  method: "HEAD",
  headers: { "X-Demo": "1" }
});
console.log(req.method);
console.log(req.headers.get("X-Demo"));
Try it Editor

How It Works

  1. init.method. HEAD.
  2. headers. Readable on req.headers.

Examples

Example 1 — clone()

Bodies can be read once.

JavaScript
const req = new Request("https://example.com", { method: "POST", body: "x" });
const c = req.clone();
console.log(c.method);
Try it Editor

How It Works

  1. clone() duplicates before reading the body.

Frequently Asked Questions

No. fetch(url, init) is enough. Request helps when you reuse or wrap requests.
Pass a string (JSON.stringify) or Blob/FormData as body.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful