JavaScript Runtime APIs - Request

The Request interface represents an HTTP request and integrates the Fetch API.

How it works

The Request object can be built and also seen as the property of a fetchevent received by edge function.

addEventListener("fetch", event => {
const request = event.request
const url = "https://example.com"
const myRequest = new Request(url, {
body: request.body,
headers: request.headers,
method: request.method,
redirect: request.redirect
})
})
addEventListener("fetch", event => {
let request = event.request
})

Constructor

let request = new Request(input [, init])

Parameters

Input: string | Request - defines the resource you want to search for by using a URL or Request object.

Init: RequestInit - optional

Properties

All properties of an initial Request object in event.request are defined as read-only. To modify a request, you must create a new Request object and pass the options to the builder, described as follows.

headers - contains an Headers object.

method - contains the request method - GET, POST, for example.

url - contains the URL request.

body - a simple” getter “to read the body’s contents through the ReadableStream interface.

bodyUsed - stores a Boolean that declares whether the request body has already been used in a response.

redirect - contains the redirection mode to use: follow, error, or manual.

event.type: string

event.request: request

For more information on Request visit MDN Web Docs.


Contributors