HttpReq
@Js
class HttpReq : Obj
HttpReq models the request side of an XMLHttpRequest instance.
See pod doc for details.
Create a new HttpReq instance
If true then perform this request asynchronously
The request headers to send
The type of data contained in the response
The Uri to send the request
Indicates whether or not cross-site Access-Control requests
should be made using credentials such as cookies, authorization
headers or TLS client certificates
Convenience for send("GET", "", c)
Optional callback to track progress of request transfers, where
loaded is the number of bytes that have been transferred, and
total is the total number of bytes to be transferred
Convenience for send("POST", content, c)
Post the form map as a HTML form submission
Post the form as a multipart/form-data submission
Convenience for send("PUT", content, c)
Send a request with the given content using the given HTTP method (case does not matter)
Bool : async
If true then perform this request asynchronously.
Defaults to true
Void get(|HttpRes| c)
Convenience for send("GET", "", c).
Str:Str : headers
The request headers to send.
new make(|This|? f := null)
Create a new HttpReq instance.
Void onProgress(|Int,Int| f)
Optional callback to track progress of request transfers, where
loaded is the number of bytes that have been transferred, and
total is the total number of bytes to be transferred.
For GET requests, the progress will track the response being
downloaded to the browser. For PUT and POST requests, the
progress will track the content being uploaded to the server.
Note this callback is only invoked when lengthComputable is
true on the underlying progress events.
Void post(Obj content, |HttpRes| c)
Convenience for send("POST", content, c).
Void postForm(Str:Str form, |HttpRes| c)
Post the form map as a HTML form submission. Formats
the map into a valid url-encoded content string, and sets
Content-Type header to application/x-www-form-urlencoded.
Void postFormMultipart(Str:Obj form, |HttpRes| c)
Post the form as a multipart/form-data submission. Formats
map into multipart key value pairs, where DomFile values will
be encoded with file contents.
Void put(Obj content, |HttpRes| c)
Convenience for send("PUT", content, c)
Str : resType
The type of data contained in the response. It also lets the
author change the response type. If an empty string is set as
the value, the default value of "text" is used. Set this
field to "arraybuffer" to access response as Buf.
Void send(Str method, Obj? content, |HttpRes| c)
Send a request with the given content using the given HTTP method (case does not matter). After receiving the response, call the given closure with the resulting HttpRes object.
Uri : uri
The Uri to send the request.
Bool : withCredentials
Indicates whether or not cross-site Access-Control requests
should be made using credentials such as cookies, authorization
headers or TLS client certificates. Setting withCredentials has
no effect on same-site requests. The default is false.
Requests from a different domain cannot set cookie values for
their own domain unless withCredentials is set to true before
making the request. The third-party cookies obtained by setting
withCredentials to true will still honor same-origin policy and
hence can not be accessed by the requesting script through
Doc.cookies or from response headers.