Versions Compared

Key

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

This server class allows operating with Use this class to operate the REST responses.

SimpleRestResponse(response)

Initialises an empty SimpleRestResponse object.

Objects of this class are created during the execution of the execute() method of the SimpleRestRequest server-side class.


Example:

Code Block
languagejs
themeEclipse
titleSimpleRestResponse
linenumberstrue
const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute();


getBody()


Use this method to get the response body.


NameTypeMandatoryDefault ValueresponseResponseYN

Return:

TypeDescription
VoidThis method does not return a value.
StringThe response body


Example:

Code Block
languagejs
themeEclipse
titleSimpleRestResponsegetBody()
linenumberstrue
const requestvar sm = sws.SimpleRestResponse(response);

getBody()

.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 get an object that contains the response headersThis method returns the response body.


Return:

TypeDescription
StringThe response body.
ObjectResponse headers


Example:

Code Block
languagejs
themeEclipse
titlegetBodygetAllHeaders()
linenumberstrue
const requestvar sm = sws.SimpleRestResponse(response.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
varconst bodyresponse = sm.getBody();

getAllHeaders()

request.execute();
ss.info(response.getAllHeaders());
// Info: {"http-code":["200"],"date":["Mon, 31...

getContentBase64()


With this method you can receive the response content encoded to base64. Use it to get the file in binary formatThis method returns the array containing response headers.


Return:

TypeDescription
ArrayResponse headers.
String or nullThe base64 encoded content


Example:

Code Block
languagejs
themeEclipse
titlegetAllHeadersgetContentBase64()
linenumberstrue
const simpleInstanceUri = ss.getProperty('simple.instance.uri');
const URL_BASE = (simpleInstanceUri.startsWith('https://')) ? simpleInstanceUri : `https://${simpleInstanceUri}`;

const requestvar sm = sws.SimpleRestResponse(response);
var headers = sm.getAllHeaders.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()


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


Return:

TypeDescription
StringThe HTTP status code
.


Example:

Code Block
languagejs
themeEclipse
titlegetStatusCode()
linenumberstrue
const requestvar sm = sws.SimpleRestResponse(response.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
varconst statusresponse = smrequest.execute();
ss.info(response.getStatusCode());
// Info: 200


haveError()


This method displays if there was an error Use this method to verify whenther any errors occured during the REST transaction.


Return:

TypeDescription
Boolean
The error notification
If some errors occured, the method returns true; otherwise, the method returns false.


Example:

Code Block
languagejs
themeEclipse
titlehaveError()
linenumberstrue
const requestvar sm = sws.SimpleRestResponceApi(response.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
varconst errorresponse = sm.getHaveErrorrequest.execute();
ss.info(response.haveError());
// Info: false


Table of Contents
absoluteUrltrue
classfixedPosition