![]() |
v1.3.0.0
|
The Response interface of the Fetch API represents the response to a request.
A Response type is returned when a Net.fetch() method promise is fulfilled, either directly in case of a successful result (passed to then() handler), or as a member of any DOMException thrown as a result of request errors (passed to catch() handler). See the local Net.fetch() documentation for details.
Properties | |
| bool | async |
| any | body |
| bool | bodyUsed |
| Headers | headers |
| bool | ok |
| bool | redirected |
| string | responseType |
| int | status |
| string | statusText |
| URL | url |
| XMLHttpRequest | xhr |
Public Member Functions | |
| < Promise< ArrayBuffer >|ArrayBuffer > | arrayBuffer () |
| Promise | bufferAsync () |
| ArrayBuffer | bufferSync () |
| < Promise< string >|string > | base64 () |
| Promise | base64Async () |
| string | base64Sync () |
| any | bodyAs (string type) |
| < Promise< Object|Array >|Object|Array > | json () |
| Promise | jsonAsync () |
| < Object|Array > | jsonSync () |
| < Promise< string >|string > | text () |
| Promise | textAsync () |
| string | textSync () |
| < Promise< XMLDocument >|XMLDocument > | xml () |
| Promise | xmlAsync () |
| XMLDocument | xmlSync () |
| Response | clone () |
| Error | blob () |
|
read |
Indicates whether the original request was made asynchronously or not.
Typically this means whether fetch() (async = true) or request() (async = false) was used to initiate the transaction.
The value determines the result type from the type-specific access methods text()/json()/arrayBuffer()/base64()/xml(); a Promise is returned from these methods when async is true, and the actual requested data type when async is false.
To explicitly get a Promise or immediate result from those access methods, use the *Sync() or *Async() versions directly. Eg. jsonSync() and jsonAsync().
This property is an alias for xhr.async.
|
read |
Returns XMLHttpRequest.response.
The return type will vary based on the responseType property set on the original Request (an ArrayBuffer, parsed JSON object/array, XML Document, or plain text).
|
read |
Returns true if response body has been parsed into a specific format (by calling body or any of the result-specific promise methods like json(), arrayBuffer(), etc).
This doesn't carry much actual significance (since it is not a data stream), but is retained for compatibility with standard.
|
read |
The Headers object associated with the response.
|
read |
A boolean indicating whether the response was successful (status in the range 200 – 299) or not.
|
read |
|
readwrite |
This possible values of this property correspond to the Request.responseType property values (both are aliases for XMLHttpRequest.responseType).
The value dictates what type of object the body property will be returned as (text, json, xml, or binary/raw). Initially this is set to whatever was set in the original Request (or fetch() options), if anything (default is blank, equivalent to "text" type). However it can also be changed after the response is received in order to affect the result type returned by body. For example based on received headers.
|
read |
The HTTP status code of the response (eg.
200 for a success, 404 not found, etc).
|
read |
The status message corresponding to the status code (eg.
"OK" for 200).
|
read |
The URL of the response.
If the request was redirected, this may not be the same as was requested.
|
read |
This is the underlying XMLHttpRequest object which actually handled the request.
All properties of the result can be read directly from this object if desired, w/out processing further promises (as with "typical" fetch() usage). For example xhr.response or xhr.responseText can be processed immediately in the first then() handler, while the usual text(), json(), etc, access methods all return further async promises for chaining.
| < Promise< ArrayBuffer >|ArrayBuffer > arrayBuffer | ( | ) |
async property is true then bufferAsync().async property is false then bufferSync().arrayBuffer() is also aliased as simply buffer().
| Promise bufferAsync | ( | ) |
Returns a Promise that resolves with an ArrayBuffer representation of the response body.
| ArrayBuffer bufferSync | ( | ) |
Returns an ArrayBuffer representation of the response body.
Same as bodyAs("arraybuffer").
| < Promise< string >|string > base64 | ( | ) |
async property is true then base64Async().async property is false then base64Sync(). | Promise base64Async | ( | ) |
Returns a Promise that resolves with an ArrayBuffer representation of the response body but encoded as a Base-64 string.
Convenience method equivalent to
to shorten to
| string base64Sync | ( | ) |
Returns an ArrayBuffer representation of the response body but encoded as a Base-64 string.
| any bodyAs | ( | string | type | ) |
Returns the response body as the given type.
The values for type are the same as for the Request.responseType property. This is equivalent to: result.responseType = type; var data = result.body;
| < Promise< Object|Array >|Object|Array > json | ( | ) |
async property is true then jsonAsync().async property is false then jsonSync(). | Promise jsonAsync | ( | ) |
Returns a Promise that resolves with the result of parsing the response body text as JSON (either a JS Object or an Array).
JSON.parse()). To ensure the result is in JSON format, first check for appropriate response header(s) before calling this method. | < Object|Array > jsonSync | ( | ) |
Returns body as the result of parsing the response body text as JSON (either a JS Object or an Array).
Same as bodyAs("json").
| < Promise< string >|string > text | ( | ) |
async property is true then textAsync().async property is false then textSync(). | Promise textAsync | ( | ) |
Returns a Promise that resolves with a text representation of the response body.
| string textSync | ( | ) |
Returns a text representation of the response body.
Same as bodyAs("text").
| < Promise< XMLDocument >|XMLDocument > xml | ( | ) |
async property is true then xmlAsync().async property is false then xmlSync(). | Promise xmlAsync | ( | ) |
Returns a Promise that resolves with an XML Document type representation of the response body.
See XMLHttpRequest for details about the available Document properties.
| XMLDocument xmlSync | ( | ) |
Returns an XMLDocument type representation of the response body.
Same as bodyAs("xml"). See XMLHttpRequest for details about the available Document properties.
| Response clone | ( | ) |
| Error blob | ( | ) |
Since Blob type is not supported in the environment, this method throws a TypeError.
Retained for compatibility with standard.