Request object
The Request object is used to represent a resource request.
Syntax
var request = new Request(input,init);
Members
The Request object has these types of members:
- Methods
- Properties
Methods
The Request object has these methods.
Method | Description |
---|---|
arrayBuffer | Takes a Response or Request stream and returns a promise for an ArrayBuffer object. |
blob | Takes a Response or Request stream and returns a promise for a Blob object. |
clone | Creates a copy of the current Request object. |
json | Takes a Response or Request stream and returns a promise for an object containing JSON data. |
text | Takes a Response or Request stream and returns a promise for a USVString object. |
Properties
The Request object has these properties.
Property | Access type | Description |
---|---|---|
Read-only |
Determines if the body is non-null and its stream is distributed. |
|
Read-only |
Contains the cache mode of the request. |
|
Read-only |
Contains the credentials mode of the request. |
|
Read-only |
Contains the destination of the request. |
|
Read-only |
Contains the Headers object of the request. |
|
Read-only |
Contains the integrity metadata of the request. |
|
Returns true if Request's keepalive flag is set. |
||
Read-only |
Contains the HTTP verb to use for the request. |
|
Read-only |
Contains the mode of the request. |
|
Read-only |
Contains the redirect mode of the request. |
|
Read-only |
Contains the referrer of the request. |
|
Read-only |
Contains the referrer policy of the request. |
|
Read-only |
Contains the type of the request. |
|
Read-only |
Contains the URL of the request. |
Standards information
Remarks
The Request constructor includes the following parameters:
Parameter | Type | Description |
---|---|---|
input | RequestInfo | Defines the resource that will be fetched. The RequestInfo type can either be a Request object or a USVString specifying the URL of the resource. |
init | RequestInit | Optional. Specifies custom settings as defined in the RequestInit dictionary. |
Dictionary of RequestInit members:
Dictionary Member | Type | Description |
---|---|---|
method | ByteString | The method of the request. |
headers | HeaderInit | A headers object to be added to the request. |
body | BodyInit | A body to be added to the request. |
referrer | USVString | The referrer of the request. |
referrerPolicy | ReferrerPolicy | The referrer policy of the request. |
mode | RequestMode | The mode of the request. |
credentials | RequestCredentials | The credentials of the request. |
cache | RequestCache | The cache mode of the request. |
redirect | RequestRedirect | The redirect mode of the request. |
integrity | DOMString | The integrity metadata of the request. |
window | any | Can only be set to null. |
keepalive | boolean | If a request's keepalive flag is set. |
ReferrerPolicy enumeration:
Value | Description |
---|---|
"" | No policy set. |
"no-referrer" | Specifies that no referrer information is to be sent along with requests made from a particular request client to any origin. The header will be omitted entirely. |
"no-referrer-when-downgrade" | Sends a full URL along with requests from TLS-protected environment settings object to a a priori authenticated URL, and requests from request clients which are not TLS-protected to any origin. |
"origin-only" | Specifies that only the ASCII serialization of the origin of the request client is sent as referrer information when making both same-origin requests and cross-origin requests from a particular request client. |
"origin-when-cross-origin" | Specifies that a full URL, stripped for use as a referrer, is sent as referrer information when making same-origin requests from a particular request client, and only the ASCII serialization of the origin of the request client is sent as referrer information when making cross-origin requests from a particular request client. |
"unsafe-url" | Specifies that a full URL, stripped for use as a referrer, is sent along with both cross-origin requests and same-origin requests made from a particular request client. |
RequestType enumeration:
Value | Description |
---|---|
"" | The destination will be "document", "", "object", or "embed". |
"audio" | The destination will be "media". |
"font" | The destination will be "font". |
"image" | The destination will be "image". |
"script" | The destination will be "script", "serviceworker", "sharedworker", or "worker". |
"style" | The destination will be "style". |
"track" | The destination will be "media". |
"video" | The destination will be "media". |
RequestDestination enumeration:
Value | Description |
---|---|
"" | The request's feature will be either navigator.sendBeacon(), EventSource, HTML's ping="", fetch(), XMLHttpRequest, WebSocket API, Cache API, HTML's download="", or "Save Link As…" UI. |
"document" | The request's feature will either be an iframe element, frame element, or HTML's navigate algorithm. |
"sharedworker" | The request's destination is a SharedWorker. |
"subresource" | The request's destination is "font", "image", "manifest", "media", "script", "style", "xslt", or the empty string. |
"unknown" | The request's destination may or may not be a navigation request. |
"worker" | The request's feature is a Worker. |
RequestMode enumeration:
Value | Description |
---|---|
"navigate" | Credentials mode is assumed to be "include" and fetch does not currently account for other values. |
"same-origin" | Requests will only be allowed for destinations same-origin with the origin. CORS will not be attempted and any request requiring CORS will result in an error. |
"no-cors" | will request the resource without enforcing the CORS protocol but will result in an OPAQUE filtered response resulting in some response properties not being available. |
"cors" | standard http request using the CORS protocol for Cross origin requests |
RequestCredentials enumeration:
Value | Description |
---|---|
"omit" | Never send cookies. The default value. |
"same-origin" | Only send cookies if being sent to a URL of the same origin. |
"include" | Always send cookies. |
RequestCache enumeration:
Value | Description |
---|---|
"default" | Fetch will inspect the HTTP cache on the way to the network. If there is a fresh response it will be used. If there is a stale response a conditional request will be created, and a normal request otherwise. It then updates the HTTP cache with the response. |
"no-store" | Fetch behaves as if there is no HTTP cache at all. |
"reload" | Fetch behaves as if there is no HTTP cache on the way to the network. Ergo, it creates a normal request and updates the HTTP cache with the response. |
"no-cache" | Fetch creates a conditional request if there is a response in the HTTP cache and a normal request otherwise. It then updates the HTTP cache with the response. |
"force-cache" | Fetch uses any response in the HTTP cache matching the request, not paying attention to staleness. If there was no response, it creates a normal request updates the HTTP cache with the response. If header list contains a header whose name is one of `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match`, and `If-Range`, fetch will set cache mode to "no-store" if it is "default". |
RequestRedirect enumeration:
Value | Description |
---|---|
"follow" | Any redirect will be followed. |
"error" | Any redirect will result in a Network Error response. |
"manual" | Any redirect will return a response with the appropriate status code and headers, but the redirect will not be followed. |