Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This class provides methods that create a response of the scripted REST API. 

Note

Object instances of this type are available as a request variable in the API Action script body.

See the Scripted REST API article to learn more.

getBody()


Use the method to get the response body.

Return:

Type

Description

AnyThis method returns the response body.

Example:

Code Block
languagejs
themeEclipse
titlegetBody()
linenumberstrue
(function(request, response) {
  response.setBody({"key":"value"});
  const responseBody = response.getBody(); // {"key":"value"}
})(SimpleApiRequest, SimpleApiResponse)

getContentType()


Use the method to get the format of the response body.

Return:

Type

Description

StringThis method returns the format of the response body.

Example:

Code Block
languagejs
themeEclipse
titlegetContentType()
linenumberstrue
(function(request, response) {
  const contentType = response.getContentType(); // application/json
})(SimpleApiRequest, SimpleApiResponse)

getHeaders()


Use the method to get the value of all request headers.

Return:

TypeDescription
Object This method returns the object that contains the keys – the header names.

Example:

Code Block
languagejs
themeEclipse
titlegetHeaders()
linenumberstrue
(function(request, response) {
    // Отправляет запрос на
    // https://your-instance-url.simpleone.ru/v1/c_simple/api_module_path/api_action_path
 
    const allHeaders = response.getHeaders(); // {"accept-encoding":["gzip, deflate, br"],"postman-token":...}
})(SimpleApiRequest, SimpleApiResponse)

getStatus()


Use the method to get the response status.

Return:

TypeDescription
IntegerThis method returns the response status.

Example:

Code Block
languagejs
themeEclipse
titlegetStatus()
linenumberstrue
(function(request, response) {
  const status = response.getStatus(); // 200
})(SimpleApiRequest, SimpleApiResponse)

setBody(body)


Use the method to set the body content of the REST response.

Parameter(s):

NameTypeMandatoryDefault value
bodyAnyYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titlesetBody()
linenumberstrue
(function(request, response) {
  response.setBody({"key":"value"});
  const responseBody = response.getBody(); // {"key":"value"}
})(SimpleApiRequest, SimpleApiResponse)

setContentType(type)


Use the method to set the format of the response body.

Parameter(s):

NameTypeMandatoryDefault value
typeStringYapplication/json

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titlesetContenType()
linenumberstrue
(function(request, response) {
  response.setContentType('text/plain');
})(SimpleApiRequest, SimpleApiResponse)

setHeader(header, value)


Use the method to set the value of the response header.

Parameter(s):

NameTypeMandatoryDefault value
headerStringYN
valueAnyYN

Return:

TypeDescription
VoidThis method does not return a value.

Пример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)

setStatus(status)


Use the method to set the HTTP status code for the response. See the list of codes to learn more.

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

Parameter(s):

NameTypeMandatoryDefault value
statusIntegerДа200

Return:

TypeDescription
VoidThis method does not return a value.

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