Skip to main content
Version: 1.24.2

SimpleRestResponse

This server class allows you to operate with the REST responses. The SimpleRestResponse object is created during the execution of the execute() method of the SimpleRestRequest server-side class.

getBody()


Use this method to return a response body.

Return:

TypeDescription
StringThis method returns the response body.
getBody()
const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute();
ss.info(response.getBody());
// Info: {
// "userId": 1,
// "id": 1,
// "title": "delectus aut autem",
// "completed": false
// }

getAllHeaders()


Use this method to return an array that contains the response headers.

Return:

TypeDescription
ObjectThis method returns the response header objects. The keys are header names and values are arrays of header values.
getAllHeaders()
const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute();
ss.info(response.getAllHeaders());
// Info: {"http-code":["200"],"date":["Mon, 31...

getContentBase64()


Use this method to return a base64 encoded content. Use it to get a file in binary format.

Return:

TypeDescription
StringThis method returns the base64 encoded content. It returns null if there is no content.
getContentBase64()
const simpleInstanceUri = ss.getProperty('simple.instance.uri');
const URL_BASE = (simpleInstanceUri.startsWith('https://')) ? simpleInstanceUri : `https://${simpleInstanceUri}`;

const request = sws.restRequestV1();
request.setRequestUrl('https://s3-home.simpleone.ru/public-attachment/4/9f/istzt33ycijsiym7rv7ax92yd76l2arr?response-content-disposition=inline%3B%20filename%3D%22spacer24.gif%22&response-content-type=image%2Fgif%3B'); //the URL from which the file is downloaded
const downloadResponse = request.execute();

request.setRequestUrl(`${URL_BASE}/v1/attachments/upload/user/${ss.getUserId()}`); // the URL on which the file is uploaded
request.setRequestHeader('Authorization', `Bearer ${new SimpleUser().getAccessToken()}`);
request.addFileContent(downloadResponse.getContentBase64(), 'files', 'spacer24.gif');
const uploadResponse = request.execute();

getStatusCode()


Use this method to return the HTTP status code of the performed request.

Return:

TypeDescription
StringThis method returns the HTTP status code.
getStatusCode()
const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute();
ss.info(response.getStatusCode());
// Info: 200

haveError()


Use this method to check whether any error occurred during the REST transaction.

Return:

TypeDescription
BooleanThe method returns true if there are any errors. Otherwise, the method returns false.
haveError()
const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute();
ss.info(response.haveError());
// Info: false