Web APIs

Request constructor

Try the free JavaScript compiler

Creates a request description without sending it. Method, headers, body and signal are supplied through options.

Formal Syntax & Structure

javascript syntaxjavascript
new Request(input, init?)

Parameters & Attributes

NameTypeDescription
inputstring | URL | RequestTarget or request to copy.
initRequestInitOptional configuration.

Return Value

Request

Constructed request.

Working Example

Example Snippetjavascript
(async () => {const r=new Request("https://example.test/items",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({qty:3})});console.log(r.method,r.headers.get("content-type"),await r.text());})()
JavaScript Reference