Last update:2026-05-18 15:35:12
The Request interface represents an HTTP request and is a core component of the standard Fetch API. In Edge Cloud Apps, you can use the Request object to read information from incoming client requests or construct new requests to initiate subrequests.
let request = new Request(input [, init])
| Parameter | Type | Required | Description |
|---|---|---|---|
| input | string | Request |
Yes | The resource to fetch. This can be a string containing a URL or an existing Request object (in which case a copy is created). |
| init | RequestInit |
No | An optional configuration object containing custom settings to apply to the Request (see details below). |
RequestInit Object Properties:
string): The HTTP request method, e.g., GET, POST. Defaults to GET.Headers): A Headers object or an object literal containing key-value pairs to set the request headers.string | ReadableStream | FormData | URLSearchParams): The body of the request. Note that requests using the GET or HEAD methods cannot have a body.string): The redirect mode to use: follow, error, or manual. When creating a new Request object via the constructor, the default is follow.
Note: For the incoming request passed to the
FetchEvent(i.e.,event.request), the redirect mode defaults tomanual.
Note: All properties of the incoming
Requestobject (event.request) are read-only. If you need to modify the incoming request, create a new Request copy by passing the necessary options to the constructor:new Request(event.request, { ...modifications }).
ReadableStream, read-only)Boolean, read-only)true.Headers, read-only)Headers object containing the request’s headers.
Important Note on Cookies: Unlike browser environments, edge functions place almost no restrictions on the headers you can send. The runtime does not manage cookies automatically; instead, it treats the
Cookieheader like any other request header, passing it through directly.Important Note on Redirect Headers: If a response is a redirect and the
redirectmode is set tofollow, all request headers (including sensitive headers likeCookie,Authorization, or custom headers) will be forwarded to the redirect target, even if the target is on a different domain. If this behavior is undesired, you should set theredirectmode tomanualand implement a custom redirect handling strategy.
string, read-only)GET or POST.string, read-only)follow, error, or manual). When set to follow, fetch() will automatically follow 3xx redirects. When set to manual, 3xx redirect responses will be returned directly to the caller.string, read-only)The following methods are available on Request instances to read and process the body:
Promise<Request>Request object.Promise<ArrayBuffer>ArrayBuffer representation.Promise<FormData>FormData object (typically used for form submissions).Promise<Object>Promise<string>When you pass a Promise that resolves to a Response into the event.respondWith() method of a fetch event, all running asynchronous tasks can safely access the active request context until that Promise settles.
Typically, you pass the event to an asynchronous handler function as shown below:
addEventListener("fetch", event => {
// Correct: Pass event.request to the async handler
event.respondWith(requestHandler(event.request));
});
// Global scope: Request context is inaccessible here
async function requestHandler(request) {
// The Request context is active and safe to use here
console.log("Request URL: ", request.url);
return new Response("Hello, Edge Cloud Apps!");
}
Attempting to call APIs like fetch() or access a specific Request context during the initial startup phase of the script (global scope) will throw an exception.
// INCORRECT: Initiating a fetch request in the global scope
const promise = fetch("https://example.com/");
addEventListener("fetch", event => {
// ...
});
The snippet above will throw an error as soon as the script loads, preventing the fetch event listener from being registered. All fetch() calls and request processing must occur inside the event listener callbacks.
When sending a request, the Content-Length header is automatically calculated and set by the runtime based on the data source of the Request. Any Content-Length value manually set in the Headers by your code will be ignored.
Content-Length, the body of the Request must be a data type with a known, fixed length (e.g., a FixedLengthStream, a string, or a TypedArray).ReadableStream (with an unknown length) as the body, the runtime will automatically utilize chunked transfer encoding (Transfer-Encoding: chunked) for transmission.