v1.2.0.1-beta1
|
The Request interface of the Fetch API represents a resource request.
Request objects can be created directly, or implicitly by passing an initializer object to Net.fetch()
or Net.request()
as the options
argument.
Additionally, request()
will return a Request
object, which has not been sent yet. The request can then be sent via one of the methods get()
, head()
, post()
, or put()
.
Request
has a static member object named Request.GlobalDefaults
which can be used to set default values on any created Request
(either implicitly created in a call to fetch()
or explicitly with new Request()
). Simply set this variable somewhere in your script with whichever default options you would like to always be set (or set them individually with Request.GlobalDefaults.property = value
). Any/all of the properties described below for the Request
object can be set this way. Properties | |
any | body = null |
string | credentials = "include" |
Headers | headers = {} |
string | method = "GET" |
bool | noThrow = false |
function | onprogress = null |
string | redirect = "no-less-safe" |
bool | rejectOnError = false |
string | responseType = "" |
AbortSignal | signal = null |
int | timeout = 30 * 1000 |
string | url = "" |
XMLHttpRequest | xhr = null |
Public Member Functions | |
< Promise|Response > | get () |
< Promise|Response > | head () |
< Promise|Response > | post (data) |
< Promise|Response > | put (data) |
Public Attributes | |
Object | GlobalDefaults = {} |
|
read |
Data for POST or PUT request.
|
readwrite |
Credentials type to use for the request; Only omit
and include
are supported.
The default is include
which is equivalent to setting XMLHttpRequest.withCredentials = true
.
|
readwrite |
The Headers
object associated with the response.
Headers can be specified a number of ways (this is the same as the standard ways of passing or creating Header
objects):
Headers
object (created with Headers(init)).name: value
pairs, for example [name, value]
pairs, for example:
|
readwrite |
HTTP method to use for the request.
One of:
|
readwrite |
This options only applies to Net.request()
.
If set to true
then Net.request()
will not throw any exceptions in case of request failure, and instead just return whatever Result is available regardless of actual status. This is a non-standard option.
|
readwrite |
Callback function for downnload/upload progress events.
The callback gets passed an object which contains the following properties:
lengthComputable
- true
or false
indicating if the total size of the requested data is available.loaded
- bytes transferred so far.total
- total bytes to transfer, if known.For more details see the XMLHttpRequest: progress event
|
readwrite |
Specifies redirect handling options.
The first 3 options are standard, the last 2 are implementation-specific:
follow
: Automatically follow redirects. Unless otherwise stated the redirect mode is set to follow.error
: Abort with an error if a redirect occurs.manual
: Caller intends to process the response in another context.no-less-safe
: (Default) Only allow http -> http, http -> https, and https -> https redirects (do not follow https -> http redirect);same-origin
: Only follow redirect if the original scheme, host, and port match.
|
readwrite |
If set to true
, Net.fetch()
will reject the promise if the returned HTTP status code is not in the 200-299 range, the same way as if a network error occurred.
See Net.fetch()
for details on the various response handling options. This is a non-standard option.
|
readwrite |
responseType
property is an enumerated string value specifying the type of data contained in the body
property (actually in XMLHttpRequest.response
).
It also lets the author change the response type. If an empty string is set as the value of responseType, the default value of text
is used. The following values are supported:
text
- The default type, interprets the response as plain text.arraybuffer
- The body will be returned as an ArrayBuffer
object of raw bytes (suitable for binary formats such as images or executables).document
- The response is an HTML or XML Document type. See XMLHttpRequest for details about the available Document
properties.json
- The response body will be parsed as JSON data into a JavaScript Object or Array.Note that the blob
response type is not available due to lack of Blob
support in the environment. Use "arraybuffer" instead.
|
readwrite |
Sets an AbortSignal
which was obtained from an AbortController
to use for aborting the network request.
This is analogous to the standard usage of this property. See AbortController @ MDN for general information and the local documentation for some implementation details.
|
readwrite |
The timeout for the network request, in milliseconds.
In case of timeout, a TimeoutError
is delivered first, followed by the generic NetworkError
type.
|
readwrite |
The URL of the request.
This is usually set in the Net.fetch(url)
or Net.request(url)
'url' parameter.
|
readwrite |
This is the underlying XMLHttpRequest object which will actually handle the request.
This is usually set up automatically by Net.fetch()
or Net.request()
, but an existing XMLHttpRequest
could be provided here instead. The XMLHttpRequest
must be in UNSENT
or OPENED
readyState
.
< Promise|Response > get | ( | ) |
Performs a "GET" request on the current url
.
async
property is true
then a Promise
object, same as Net.fetch()
would return.async
property is false
then a Response
object, same as Net.request()
would return. < Promise|Response > head | ( | ) |
Performs a "HEAD" request on the current url
.
async
property is true
then a Promise
object, same as Net.fetch()
would return.async
property is false
then a Response
object, same as Net.request()
would return. < Promise|Response > post | ( | data | ) |
Performs a "POST" request on the current url
.
data | The data to send in the post request body, if any. |
async
property is true
then a Promise
object, same as Net.fetch()
would return.async
property is false
then a Response
object, same as Net.request()
would return. < Promise|Response > put | ( | data | ) |
Performs a "PUT" request on the current url
.
data | The data to send in the put request body, if any. |
async
property is true
then a Promise
object, same as Net.fetch()
would return.async
property is false
then a Response
object, same as Net.request()
would return. Object GlobalDefaults = {} |
This global static object can be used to set default values on any created Request
(either implicitly created in a call to fetch()
or explicitly with new Request()
).
Simply set this variable somewhere in your script with whichever default options you would like to always be set (or set them individually with Request.GlobalDefaults.property = value
). Any/all of the properties described below for the Request
object can be set this way.