rbv_api.setResponseBody()

Purpose

This is an optional API, which overrides default response options like statusCode, statusMessage, headers or Content-Type.

You can execute the return response from custom API by any of the following methods:

  1. A simple return statement in which case
    • statusCode defaults to 200.
    • statusMessage defaults to OK.
    • body constitutes the return value.
    • Content-Type defaults to application/json.
  2. Using setResponseBody() method. If set, any return value from script is disregarded.

Syntax

rbv_api.setResponseBody(code, message, body, headers, contentType);

Parameters

code

A valid HTTP status code (integer).

message

A message describing the status code (string)

body

A valid response body complying to given Content-Type (string)

headers

A simple key value map comprising custom headers value { String : String, ...}

contentType

A valid HTTP Content-Type value (String)

 

Example

var success = .... / developer logic

if (success) {

rbv_api.setResponseBody(202, "Accepted", "Record Created" , {'statusCodes' : true}, "application/xml");

} else {

rbv_api.setResponseBody(429, "Too Many Requests", "Couldn't receive response from third party service", {'numRetries' : '3','retryInterval' : '2000'}, "text/xml");

}