You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 9 Next »
This server class allows operating with REST responses.
Return:
Example:
const request = sws.restRequestV1(); request.setRequestUrl('https://jsonplaceholder.typicode.com/todos/1'); request.setRequestMethod('GET'); const response = request.execute();
This method returns the response body.
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 // }
This method returns the array containing response headers.
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...
This method returns the HTTP status code of the request performed.
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
This method displays if there was an error during the REST transaction.
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