Request

Request

Creates a new Request object representing a resource request that can be passed to fetch()

Syntax

JavaScript
new Request(input, init?)

Parameters

ParameterTypeDescription
inputstring | URL | RequestThe URL or an existing Request to clone
initRequestInitOptions: method, headers, body, mode, credentials, cache, redirect, signal

Return Value

A new Request object

Examples

Basic Usage
const request = new Request('/api/users', {
  method: 'GET',
  headers: { 'Accept': 'application/json' }
})
const response = await fetch(request)
Practical Example
const request = new Request('/api/data', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Alice' })
})
console.log(request.method) // 'POST'
Advanced Usage
const base = new Request('/api', {
  headers: { 'Authorization': 'Bearer token123' }
})
const cloned = new Request(base, { method: 'PUT' })
console.log(cloned.method) // 'PUT'

Understanding Request

The Request method in JavaScript creates a new Request object representing a resource request that can be passed to fetch(). It belongs to the Request object and is one of the most widely used methods for working with request values in modern JavaScript and TypeScript applications.

The method signature is new Request(input, init?). It accepts 2 parameters: input, init. When called, it returns a new request object. Understanding when and how to use Request() helps you write more expressive, readable code.

Common use cases for Request include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like response-constructor, fetch-headers-constructor, fetch-response-json, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Request is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

Related Tools

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.