Versions Compared

Key

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

Этот класс содержит методы для работы с ответами REST. Объекты этого класса создаются во время выполнения метода execute() серверного класса SimpleRestRequest.

Пример

This server class allows you to operate with the REST responses.

SimpleRestResponse(response)

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

Return:

TypeDescriptionVoidThis method does not return a value.

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()

This method returns a response body.

Return:

TypeDescriptionStringThe response body.

Используйте метод, чтобы получить тело ответа.

Возвращаемое значение:

ТипОписание
StringМетод возвращает тело ответа.

ПримерExample:

Code Block
languagejs
themeEclipse
titlegetBody()
linenumberstrue
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 an array containing the response headers.

Return:

TypeDescriptionObjectResponse headers.

Используйте метод, чтобы получить объект, содержащий заголовки ответа.

Возвращаемое значение:

ТипОписание
ObjectМетод возвращает объекты заголовков ответа. Ключи – это названия заголовков, а значения – это массивы значений заголовков.

ПримерExample:

Code Block
languagejs
themeEclipse
titlegetAllHeaders()
linenumberstrue
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 a base64 encoded content. Use it to get a file in binary format.

Return:

TypeDescriptionStringThe base64 encoded content.

Используйте метод, чтобы получить содержимое ответа в кодировке base64. Используйте его, чтобы получить файл в двоичном формате.

Возвращаемое значение:

ТипОписание
StringМетод возвращает содержимое ответа в кодировке base64. Метод возвращает null, если нет содержимого.

ПримерExample:

Code Block
languagejs
themeEclipse
titlegetContentBase64()
linenumberstrue
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.

Return:

TypeDescriptionStringHTTP status code.

Используйте метод, чтобы получить код состояния HTTP выполненного запроса.

Возвращаемое значение:

ТипОписание
StringМетод возвращает код состояния HTTP.

ПримерExample:

Code Block
languagejs
themeEclipse
titlegetStatusCode()
linenumberstrue
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 an error was reported during the REST transaction.

Return:

TypeDescriptionBooleanThe error notification.

Используйте этот метод, чтобы проверить наличие ошибок, произошедших во время транзакции REST.

Возвращаемое значение:

ТипОписание
BooleanМетод возвращает true при наличии ошибок. Если ошибок не было, метод возвращает false.

ПримерExample:

Code Block
languagejs
themeEclipse
titlehaveError()
linenumberstrue
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
absoluteUrltrue
classfixedPosition