HTTPRequest

From Web Computing Documentation
Jump to: navigation, search

class HTTPRequest

  • web2grid
    • web2grid.core
      • web2grid.core.net
        • web2grid.core.net.HTTPRequest

Class overview

The HTTPRequest object offers an easy to use cross-browser tool to execute GET, POST and PUT commands utilizing cross-origin resource sharing if necessary.

Public functions

get (url : String) : HTTPRequest

url The url of the target of the request.

Returns a GET HTTPRequest targeted at the specified URL. Use the send function to execute the request.

post (url : String) : HTTPRequest

url The url of the target of the request.

Returns a POST HTTPRequest targeted at the specified URL. Use the send function to execute the request.

put (url : String) : HTTPRequest

url The url of the target of the request.

Returns a PUT HTTPRequest targeted at the specified URL. Use the send function to execute the request.

send () : AsyncResult<HTTPRequest>

Starts the request. Before calling this function you should use either of the previous three functions to set up the object properly.

rawData (data : String)

data The data to be sent.

Using this function you can set up the HTTPRequest object for sending data.

addParam (key : String, value : String)

key The key for the url parameter.
value The url encoded value for the given key.

Sets url encoded paramters.

successCallback (successCallback : HTTPResponse -> Void)

successCallback The callback function taking an HTTPResponse object as a parameter, returning Void.

successCallback sets a callback function for the event of successful completion.

errorCallback (errorCallback: String -> Void)

errorCallback The callback function taking a String object as a parameter, returning Void.

errorCallback sets a callback function for the event of erroneous completion.

progressCallback (progressCallback: Float -> Void)

progressCallback The callback function taking a Float object as a parameter, returning Void.

progressCallback sets a callback function for the event of progress change. An input parameter of 0 indicates 0% while 1.0 indicates 100%.

Example

var myHTTPRequest = HTTPRequest.get("http://domain.com").send();
myHTTPRequest.onComplete.subscribe(function(response : HTTPResponse)
{
    dostuff(response.content);
});

In the example we subscribed to the onComplete event of the returned AsyncResult object.

Personal tools
Modules