Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
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:
Name | Type | Mandatory | Default Value |
---|---|---|---|
body | Object | Y | N |
body | TypeString | Description | Void | This method does not return a value.Y | N |
---|
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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:
Name | Type | Mandatory | Default Value |
---|---|---|---|
header | String | Y | N |
value | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
(function (request, response) { response.setHeader('BACKEND-VERSION', ss.getProperty('simple.version.back')); response.setHeader("Location","<URI>");'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:
Name | Type | Mandatory | Default Value |
---|---|---|---|
headers | Object | Y | N |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
let headers = {}; headers['X-Total-Count']=100; headers.Location='https://<your_instance_url>/<resource_endpoint>'; response.setHeaders(headers);(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 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:
Name | Type | Mandatory | Default Value |
---|---|---|---|
Status | Integer | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value.
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
(function (request, response) { response.setBody({ "support_phone": ss.getProperty('simple.auth_page.support_phone') }); response.setStatus(200); })(SimpleApiRequest, SimpleApiResponse) |
Table of Contents | ||||||
---|---|---|---|---|---|---|
|