rbf_sendHttpRequest

Purpose

Platform client-side API to provide end-users the ability to invoke RESTful web services from within a Platform page. This API will be available for Platform Application pages and Portal pages and can be leveraged in Custom Script Components. This API will be available in portal pages only if the AJAX calls are enabled for portal users.

Note: This method can use server-side tokens ensuring that logged-in users do not see the resolved value on client-side. You can achieve this by using the syntax {\u0021#tokenName}. This provides a very secure solution when you need to use secret keys in API calls.

Syntax

rbf_sendHttpRequest(url, method, headers, params, body, options)			
			

Parameters

url

The REST Service URL. This function argument is mandatory.

method

The HTTP method. This function argument is mandatory. The POST, GET, PUT, and DELETE HTTP Methods are supported.

headers

The JSON object with key-value pairs to be forwarded as HTTP Request headers.

params

The JSON object with key-value pairs, wherein, each entry denotes HTTP Request parameter name and parameter value.

body

The request payload as serialized string literal.

options

The JSON object with additional optional arguments as properties.

Property NameDescription
callbackCallback function handler. This API has asynchronous behavior. The service response is passed as an JSON object (function argument) to this callback function. This JSON object encapsulates the response status code, headers, and payload.
errorCallbackThe error details will be passed as arguments to this error callback handler. If this callback handler is not configured, use the global error handler function 'rbv_errorsCallback'.
userNameOn Platform server side, while establishing HTTP connection to RESTful Service host, Platform supports HTTP Basic Authentication. You must pass the user-name details as this property value. You can also set Platform token as the property value. The Platform token will be resolved and used in the Authorization header of the HTTP request.
passwordOn Platform server side, while establishing HTTP connection to RESTful Service host, Platform supports HTTP Basic Authentication. You must pass password as this property value. You can also set Platform token as property value. The Platform token will be resolved and used in the Authorization header of the HTTP request.
httpReadTimeoutThis property configures socket read timeout for the HTTP connection in milliseconds. That default value is 2 minutes. However, this can be configured to a maximum of 8 minutes.
debugThis property logs debug messages (tenant specific) on Platform server-side, while relaying service request and response.
timeoutThis property configures AJAX call timeout in milliseconds. The default value is 5 minutes. However, this can be configured to a maximum of 15 minutes using this property. On exceeding this period, AJAX call will timeout and result in a timeout error response.

Note: This method is allowed only for REST service host white-listed by the administrator. Refer Editing applications. The server-side token resolution is available for the CURR_USER , CURR_VISIT (Portal Visitor) , SETTINGS, and CURR_CUSTM objects.

Limitations

As this API is primarily client-side, it deals with HTTP request and response payload content-types such as text/plain, application/xml, and application/json.

HTTP requests with content-type multipart/form-data are not supported.

Tokens

You can use tokens as API arguments and enforce that these tokens can be evaluated on server side as a part of API call. For this, you need to escape tokens. For example, a token like ‘{!SETTINGS.PASSWORD}’, should be embedded in script as ‘{\u0021SETTINGS. PASSWORD }’. The other option is to use string concatenation as ‘{‘+’!SETTINGS. PASSWORD }’.

Note: This API is supported in portals as well.

Example

<script>
  function processExchangeRates(resp) {
      if (resp.status == 200) {
          var node = $.parseXML(resp.body); //parse xml string literal
          var currRate = $(node).find('Rate').text();
      }
  }

  rbf_sendHttpRequest('http://query.yahooapis.com/v1/public/yql', //url
      'GET', //http method
      {
          'Accept': 'text/xml'
      }, // headers
      {
          'q': 'select * from yahoo.finance.xchange where pair in ("USDEUR")',
          'env': 'store://datatables.org/alltableswithkeys'
      }, // params
      null, //body
      {
          callback: processExchangeRates
      } //options
  );
</script>