This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.
The Request interface of the Fetch API represents a resource request.
You can create a new Request object using the Request.Request() constructor, but you are more likely to encounter a Request object being returned as the result of another API operation, such as a service worker Fetchevent.request.
Constructor
Request.Request()- Creates a new
Requestobject.
Properties
Request.methodRead only- Contains the request's method (
GET,POST, etc.) Request.urlRead only- Contains the URL of the request.
Request.headersRead only- Contains the associated
Headersobject of the request. Request.contextRead only- Contains the context of the request (e.g.,
audio,image,iframe, etc.) Request.referrerRead only- Contains the referrer of the request (e.g.,
client). Request.modeRead only- Contains the mode of the request (e.g.,
cors,no-cors,same-origin). Request.credentialsRead only- Contains the credentials of the request (e.g.,
omit,same-origin). Request.integrityRead only- Contains the subresource integrity value of the request (e.g.,
sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=). Request.cacheRead only- Contains the cache mode of the request (e.g.,
default,reload,no-cache).
Request implements Body, so it also has the following property available to it:
Body.bodyUsedRead only- Stores a
Booleanthat declares whether the body has been used in a response yet.
Methods
Request.clone()- Creates a copy of the current
Requestobject.
Request implements Body, so it also has the following methods available to it:
Body.arrayBuffer()- Takes a
Responsestream and reads it to completion. It returns a promise that resolves with anArrayBuffer. Body.blob()- Takes a
Responsestream and reads it to completion. It returns a promise that resolves with aBlob. Body.formData()- Takes a
Responsestream and reads it to completion. It returns a promise that resolves with aFormDataobject. Body.json()- Takes a
Responsestream and reads it to completion. It returns a promise that resolves with aJSONobject. Body.text()- Takes a
Responsestream and reads it to completion. It returns a promise that resolves with aUSVString(text).
Examples
In the following snippet, we create a new request using the Request() constructor (for an image file in the same directory as the script), then return some property values of the request:
var myRequest = new Request('flowers.jpg');
var myURL = myRequest.url; // http://localhost:8000/flowers.jpg
var myMethod = myRequest.method; // GET
var myCred = myRequest.credentials; // omit
You could then fetch this request by passing the Request object in as a parameter to a GlobalFetch.fetch() call, for example:
fetch(myRequest).then(function(response) {
return response.blob();
}).then(function(response) {
var objectURL = URL.createObjectURL(response);
myImage.src = objectURL;
});
Specifications
| Specification | Status | Comment |
|---|---|---|
| Fetch The definition of 'Request' in that specification. |
Living Standard | Initial definition |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support |
42 |
39 (39) 34[1] |
Not supported |
29 |
Not supported |
| Request.integrity | 45 | Not supported | Not supported |
| Feature | Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|
| Basic support | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported |
[1] This feature is implemented behind a preference.

