ExternalResource.js

These functions allow you to access resources on external HTTP servers.

Function Description
getExternalResource(url, options) Makes a request to access resources on an external HTTP server.
  • options – a set of key/value pairs that configure the underlying request. Supported options are:
    • method – one of GET, PUT, DELETE, HEAD, OPTIONS, or POST. The default is GET.
    • HTTP and HTTPS are supported.
    • async – request should be sent asynchronously. The default is true.
    • headers – request headers to be sent with request.
    • data – data to be sent. If this is an array, it is converted to a query string. For a GET request, this is added to the end of the URL.
    • complete – callback for when this method completes.
Note: An X.509 certificate blob (used in SSO) cannot be used as a client certificate for HTTPS communication. In other words, you can use only client certificates from trusted certificate authorities, which means that self-signed certificates do not work.
complete( resultXHR ) The complete(resultXHR) callback is sent when getExternalResource finishes. Its input is a resultXHR structure which closely mirrors the JavaScript XmlHttpRequest object.
The fields/methods available on resultXHR are:
  • status
  • statusText
  • responesText
  • getReponseHeader(key)
  • getAllResponesHeaders()
These fields and methods are not supported for resultXHR:
  • open()
  • setRequestHeader()
  • responseXML
  • send()
  • abort()

Example 1

This shows an example of the UPDATE function:
function update() {
        // Using json to update a value
        var url = // URL of your external resource;
        var webResponse;
        var options = {
            method: "PUT",
            data: "{\"Value\":\"Value A Updated\"}",
            headers: {
                "Content-type": "application/json"
            },
            async: false,
            complete: function(response) { webResponse = response; }
        };

        getExternalResource(url, options);

        if (webResponse.status === 200)
        	alert("Update successful");
        else
        	alert("Update Failed");
}

Example 2

This shows an example of the DELETE function:
function delete() {
	  // Delete a value
        var url = // URL of your external resource;
        var webResponse;
        var options = {
            method: "DELETE",
            async: false,
            complete: function(response) { webResponse = response; }
        };

        getExternalResource(url, options);

        if (webResponse.status === 200)
        	alert("Delete successful");
        else
        	alert("Delete Failed");
}