Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Comment:
Merged branch "DOC0000565" into parent
This server class allows operating you to operate with REST responses.
SimpleRestResponse(response)
Objects of this class are created within invoking during the execution of the execute() method of the SimpleRestRequest server-side class.
Name | Type | Mandatory | Default Value |
---|---|---|---|
response | Response | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[const request = sws.restRequestV1();
request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1');
request.setRequestMethod('GET');
const response = request.execute(); |
getBody()
This method returns the response body.
Return:
Type | Description |
---|---|
String | The response body. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[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()
This method returns the array containing response headers.
Return:
Type | Description |
---|---|
Object | Response headers. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[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()
This method returns base64 encoded content. It is useful for getting a file in binary format.
Return:
Type | Description |
---|---|
String | The base64 encoded content. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[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()
This method returns the HTTP status code of the performed request performed.
Return:
Type | Description |
---|---|
String | HTTP status code. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[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()
This method displays an error notification if there was an error was reported during the REST transaction.
Return:
Type | Description |
---|---|
Boolean | The error notification. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<![CDATA[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 |
Table of Contents | ||||
---|---|---|---|---|
|