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
Return:
TypeDescription
bodyStringY
VoidThis method does not return a value.
N


Example:

Code Block
languagejs
themeEclipse
titlesetBody
linenumberstrue
let body =(function (request, response) {};
body.name = 'incident';
body.number = '1234';
body.caller = {'id': 'user1'};
response.setBody(body);  response.setBody({
    "status": "ok",
    "support_phone": ss.getProperty('simple.auth_page.support_phone')
  });
})(SimpleApiRequest, SimpleApiResponse)

setHeader(header, value)


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

Parameters:

NameTypeMandatoryDefault Value
headerStringYN
valueStringYN

Return:

This method does not return a value.
TypeDescription
Void


Example:

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

setHeaders(headers)


Sets the This method allows to define headers for the web service REST response.


Parameters:

NameTypeMandatoryDefault Value
headersObjectYN


Example:

Code Block
languagejs
themeEclipse
titlesetHeaders
linenumberstrue
let headers =(function (request, response) {};
headers.X-Total-Count=100;
headers.Location='https://instance.simpleone.ru/<endpoint_to_resource>';
response.setHeaders(headers);  response.setHeaders({
    'BACKEND-VERSION': ss.getProperty('simple.version.back'),
    'FRONTEND-VERSION': ss.getProperty('simple.version.front')
  });
})(SimpleApiRequest, SimpleApiResponse)

setStatus(status)


This method sets 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

Return:

This method does not return a value.
TypeDescription
Void


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