JavaScript Client SDK
Class Index | File Index

Classes


Class HTTPAgent

Use the HTTPAgent class to make requests to the server. The HTTPAgent class composes jquery data requests for specific CRUD operations. It checks connectivity and can wrap all errors in a common exception object, the AK.ServerException. For example, if a certain API requires a given Content-Type header to be sent with every request, this can be set in a custom API-specific HTTPAgent rather than specifying it in each request's options.

Include the log in token in the headers for any request to the Akula server that requires authorization. The token is automatically stored in the AK.Session.current.token property after a successful call to the AK.Session.login() method. The following example passes the token as part of an HTTP GET request:

function listAccess() {

   var params = {
     headers:{"Accept":"application/json",
               "X-Ak-Session-Id":AK.Session.current.token}
   };

   var myAgent = new AK.HTTPAgent(params);

   // Use a GET request to read data from the data source.
   myAgent.get("http://myServer.com/akula/ToDo/data/tasks", {}, callback);
 };

The del(), get(), post(), and put() methods all take an optional callback parameter that defines the success(), error(), and complete() callback methods. You must define the callback object before passing it to these methods, as shown below:

// Define callback methods to handle response events.
var callback = {
    success : function(data, textStatus, jqXHR) {
        console.log("Request success! " + data );
    },
    error : function(exception) {
         // In the error() method, determine the type of the exception object.
          if(exception instanceof AK.ServerException)
              log("Got a ServerException " + exception.code + ", " + exception.message +
                 ", httpstatus:" + exception.httpStatus);
          else
              log("Got an Exception " + exception.message);
    },
    complete: function(jqXHR, textStatus) {
        console.log("Request complete");
    }
};

The success() callback is called when the request returns successfully. It is called with three arguments representing the response data, a text status message, and the jQuery jqXHR object representing the http request.

The error() method is called when the request fails. It takes a single argument containing an exception object. In the error() method, you can determine the type of exception object.

The complete() method is called when the request completes, regardless of success or error. It is called with two arguments representing the jQuery jqXHR object, and a test status message. See http://api.jquery.com/jQuery.ajax/#jqXHR for details on the jqXHR object.


Defined in: HTTPAgent.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
HTTPAgent(settings)
Creates a new HTTPAgent object.
Method Summary
Method Attributes Method Name and Description
 
del(url, options, callback)
Send an HTTP DELETE request through jQuery, bundling the preset settings into the request.
 
get(url, options, callback)
Send an HTTP GET request through jQuery, bundling the preset settings into the request.
 
post(url, data, options, callback)
Send an HTTP POST request through jQuery, bundling the preset settings into the request.
 
put(url, data, options, callback)
Send an HTTP PUT request through jQuery, bundling the preset settings into the request.
 
request(options)
Send a raw jQuery.ajax request throught jQuery.ajax, bundling the preset settings into the request.
Class Detail
HTTPAgent(settings)
Creates a new HTTPAgent object.
Parameters:
{Object} settings
A jQuery.ajax() compatible settings object containing the settings to be included with every request. See http://api.jquery.com/jQuery.ajax for details.
Since:
1.0
Method Detail
{jqXHR} del(url, options, callback)
Send an HTTP DELETE request through jQuery, bundling the preset settings into the request.
Parameters:
{String} url
The request URL.
{Object} options Optional
A jQuery.ajax() compatible settings object containing any desired per-request custom options. See http://api.jquery.com/jQuery.ajax for details.
{Object} callback Optional
Callback container that defines the success(), error(), and complete() callback methods.
Since:
1.0
Returns:
{jqXHR} The jqXHR object associated with the request. See http://api.jquery.com/jQuery.ajax/#jqXHR for details.
{jqXHR} get(url, options, callback)
Send an HTTP GET request through jQuery, bundling the preset settings into the request.
Parameters:
{String} url
The request URL.
{Object} options Optional
A jQuery.ajax() compatible settings object containing any desired per-request custom options. See http://api.jquery.com/jQuery.ajax for details.
{Object} callback Optional
Callback container that defines the success(), error(), and complete() callback methods.
Since:
1.0
Returns:
{jqXHR} The jqXHR object associated with the request. See http://api.jquery.com/jQuery.ajax/#jqXHR for details.
{jqXHR} post(url, data, options, callback)
Send an HTTP POST request through jQuery, bundling the preset settings into the request.
Parameters:
{String} url
The request URL.
{Object} data
The data object to be created on the server.
{Object} options Optional
A jQuery.ajax() compatible settings object containing any desired per-request custom options. See http://api.jquery.com/jQuery.ajax for details.
{Object} callback Optional
Callback container that defines the success(), error(), and complete() callback methods.
Since:
1.0
Returns:
{jqXHR} The jqXHR object associated with the request. See http://api.jquery.com/jQuery.ajax/#jqXHR for details.
{jqXHR} put(url, data, options, callback)
Send an HTTP PUT request through jQuery, bundling the preset settings into the request.
Parameters:
{String} url
The request URL.
{Object} data
The data object to be applied as a change on the server.
{Object} options Optional
A jQuery.ajax() compatible settings object containing any desired per-request custom options. See http://api.jquery.com/jQuery.ajax for details.
{Object} callback Optional
Callback container that defines the success(), error(), and complete() callback methods.
Since:
1.0
Returns:
{jqXHR} The jqXHR object associated with the request. See http://api.jquery.com/jQuery.ajax/#jqXHR for details.
{jqXHR} request(options)
Send a raw jQuery.ajax request throught jQuery.ajax, bundling the preset settings into the request.
Parameters:
{Object} options Optional
A jQuery.ajax() compatible settings object containing any desired per-request custom options. See http://api.jquery.com/jQuery.ajax for details.
Since:
1.0
Returns:
{jqXHR} The jqXHR object associated with the request. See http://api.jquery.com/jQuery.ajax/#jqXHR for details.

©2013 Verivo Software, Inc. Documentation generated by JsDoc Toolkit 2.4.0 on Mon Apr 27 2015 15:06:19 GMT-0400 (EDT)