Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Merged branch "DOC0000160" into parent

This class helps you to create a REST response to a scripted REST API Request.

Note

Objects of this type cannot be instantiated and created automatically. They are accessible within the API action script body by the request variable. 

For more information, please refer to the Configuring Scripted REST API article.

setBody(body)


Sets the response contentThis method returns the body content within the REST response. Response body is returned in JSON format.


Parameter:

NameTypeMandatoryDefault Value
bodyObjectYN
bodyStringYN

Return:

TypeDescriptionVoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetBody
linenumberstrue
(function (request, response) {
  response.setBody({
    "status": "ok",
    "support_phone": ss.getProperty('simple.auth_page.support_phone')
  });
})(SimpleApiRequest, SimpleApiResponse)

setHeader(header, value)


This method allows to set a value to a REST response header. 

Parameters:

NameTypeMandatoryDefault Value
headerStringYN
valueStringYN


Example:

Code Block
languagejs
themeEclipse
titlesetHeader
linenumberstrue
(function (request, response) {
  response.setHeader('BACKEND-VERSION', ss.getProperty('simple.version.back'));
  response.setHeader('FRONTEND-VERSION', ss.getProperty('simple.version.front'));
})(SimpleApiRequest, SimpleApiResponse)

setHeaders(headers)


This method allows to define headers for REST response.


Parameters:

NameTypeMandatoryDefault Value
headersObjectYN


Example:

Code Block
languagejs
themeEclipse
titlesetHeaders
linenumberstrue
(function (request, response) {
  response.setHeaders({
    'BACKEND-VERSION': ss.getProperty('simple.version.back'),
    'FRONTEND-VERSION': ss.getProperty('simple.version.front')
  });
})(SimpleApiRequest, SimpleApiResponse)

setStatus(status)


This method sets the HTTP status code number for the service response. To get the information about status code returned, please refer to the status code list.

For example, the status code 200 is for success, and the status code 404 denotes that the requested URI was not found.


Parameters:

NameTypeMandatoryDefault Value
StatusIntegerYN


Example:

Code Block
languagejs
themeEclipse
titlesetStatus
linenumberstrue
(function (request, response) {
  response.setBody({
    "support_phone": ss.getProperty('simple.auth_page.support_phone')
  });
  response.setStatus(200);
})(SimpleApiRequest, SimpleApiResponse)


Table of Contents
absoluteUrltrue
classfixedPosition
printablefalse