JavaScripture
Contribute via GitHub Feedback

JavaScript Request : Object

Request is used to describe an request to a server. Use with fetch() to perform the request and get a Response. Request, fetch(), and Response are a new, low level replacement for XMLHttpRequest.

Constructors

new Request(url : String, [init : Object]) : Request
init : {
bodyObjectThe data to send with the request. Must be a Blob, BufferSource, FormData, String, or URLSearchParams.
cacheStringSee the cache property for the valid values.
credentialsStringSee the credentials property for the valid values.
headersObjectThe http headers to send with the request. This will be passed to the Headers constructor.
integrityString
keepaliveBoolean
methodStringThe http method such as 'GET', 'POST', 'DELETE'.
modeStringSee the mode property for the valid values.
redirectStringOne of 'follow', 'error', or 'manual'
referrerString
referrerPolicyStringOne of '', 'no-referrer', 'no-referrer-when-downgrade', 'same-origin', 'origin', 'strict-origin', 'origin-when-cross-origin', 'strict-origin-when-cross-origin', or 'unsafe-url'
requestModeStringOne of 'navigate', 'same-origin', 'no-cors', or 'cors'
requestCredentialsStringOne of 'omit', 'same-origin', or 'include'
signalAbortSignal
}

Example:

Run

Results:

 

new Request(request : Request, [init : Object]) : Request

Instance Properties

bodyUsed : Boolean  

cache : String  

Will be one of: 'default', 'force-cache', 'no-cache', 'no-store', 'only-if-cached', 'reload'.

credentials : String  

Will be one of: 'include', 'omit', 'same-origin'.

destination : String  

Will be one of: '', 'audio', 'audioworklet', 'document', 'embed', 'font', 'frame', 'iframe', 'image', 'manifest', 'object', 'paintworklet', 'report', 'script', 'sharedworker', 'style', 'track', 'video', 'worker', 'xslt'.

headers : Headers  

integrity : String  

isHistoryNavigation : Boolean  

isReloadNavigation : Boolean  

keepalive : Boolean  

method : String  

mode : String  

Will be one of: 'same-origin', 'no-cors', 'cors'.

redirect : String  

referrer : String  

referrerPolicy : String  

signal : AbortSignal  

url : String  

Instance Methods

arrayBuffer() : Promise<ArrayBuffer>

Returns a Promise to the body of the request as an ArrayBuffer.

Example:

Run

Results:

 

blob() : Promise<Blob>

Returns a Promise to the body of the request as a Blob.

Example:

Run

Results:

 

clone() : Request

formData() : Promise<FormData>

Returns a Promise to the body of the request as a FormData.

json() : Promise<Object>

Parses the body of the request and returns a Promise with the result.

Example:

Run

Results:

 

text() : Promise<String>

Returns a Promise to the body of the request.

Example:

Run

Results: