RESTService

This behavior pattern implements REST service client.

Extends SeSSimulatedObject

Behavior Pattern: RESTServiceBehavior

Property Summary

Property Description Getter Setter
Credential The HTTP Basic Authentication Credentials (if any). GetCredential SetCredential
Method The HTTP Method being used for the request (GET, POST, etc. GetMethod SetMethod
Name The name of the request operation GetName
Parameters The list of parameters available for this request url. GetParameters SetParameters
RequestBodyObject The body of the HTTP request as a JavaScript object. GetRequestBodyObject SetRequestBodyObject
RequestBodyText The body of the HTTP request in raw text format GetRequestBodyText SetRequestBodyText
RequestHeaders The list of HTTP headers that are part of this request. GetRequestHeaders SetRequestHeaders
ResponseBodyObject The body of the HTTP response deserialized from JSON into a JavaScript object. GetResponseBodyObject
ResponseBodyText The body of the HTTP response in raw text format GetResponseBodyText
ResponseHeaders Returns the list of HTTP headers returned from the HTTP response. GetResponseHeaders
ResponseIsErrorStatus Returns 'true 'if an HTTP error code came back from the web service GetResponseIsErrorStatus
Url The URL being used to access the web service GetUrl SetUrl

Action Summary

Action Description
DoExecute Executes a REST service operation, substitutes any of the provided parameter values if necessary.
DoVerify Checks that a given part of response equals the expected value.

Property Detail

Credential

The HTTP Basic Authentication Credentials (if any).
Sample code:

var credential = {};credential.UserName = "fredbloggs";credential.Password = "MyPassword";SeS("Operation_Name").SetCredential(credential);

Another way is to pass user name and password as first and second parameter respectively, e.g. SeS("Operation_Name").SetCredential("fredbloggs", "MyPassword");

Type: object

Accessors: GetCredential, SetCredential

Method

The HTTP Method being used for the request (GET, POST, etc.)

Type: string

Accessors: GetMethod, SetMethod

Name

The name of the request operation

Type: string

Accessors: GetName

Parameters

The list of parameters available for this request url.
Sample code:

var parameters = SeS("Operation_Name").GetParameters();for (var i = 0; i < parameters.length; i++){ var name = parameters[i].Name; var token = parameters[i].TokenName; var value = parameters[i].Value;}

Type: object

Accessors: GetParameters, SetParameters

RequestBodyObject

The body of the HTTP request as a JavaScript object.
Sample code:

var book = {};book.Name = "A Christmas Carol";book.AuthorId = 2;book.GenreId = 3;SeS("LibraryInformationSystem_Insert_Book").SetRequestBodyObject(book);SeS("LibraryInformationSystem_Insert_Book").DoExecute({"session_id":sessionId});

Type: object

Accessors: GetRequestBodyObject, SetRequestBodyObject

RequestBodyText

The body of the HTTP request in raw text format

Type: string

Accessors: GetRequestBodyText, SetRequestBodyText

RequestHeaders

The list of HTTP headers that are part of this request.
Sample code:

var headers = SeS("Operation_Name").GetRequestHeaders();for (var i = 0; i < headers.length; i++){ var name = headers[i].Name; var value = headers[i].Value;}

Type: object

Accessors: GetRequestHeaders, SetRequestHeaders

ResponseBodyObject

The body of the HTTP response deserialized from JSON into a JavaScript object.
Sample code:

SeS("LibraryInformationSystem_Get_BookById").DoExecute({"session_id":sessionId, "book_id":bookId});var book = SeS("LibraryInformationSystem_Get_BookById").GetResponseBodyObject();

Getter Parameters:

Name Type Description
jsonPath string Path to a sub-object within response object. E.g. 'Body.Connection_AuthenticateResult'.
Optional, Default: Body.
info object Empty object that will receive error information if any. Access as info.error in a calling function.
Optional.

Type: object

Accessors: GetResponseBodyObject

ResponseBodyText

The body of the HTTP response in raw text format

Type: string

Accessors: GetResponseBodyText

ResponseHeaders

Returns the list of HTTP headers returned from the HTTP response.
Sample code:

var headers = SeS("Operation_Name").GetResponseHeaders();for (var i = 0; i < headers.length; i++){ var name = headers[i].Name; var value = headers[i].Value;}

Type: object

Accessors: GetResponseHeaders

ResponseIsErrorStatus

Returns 'true 'if an HTTP error code came back from the web service

Type: boolean

Accessors: GetResponseIsErrorStatus

Url

The URL being used to access the web service

Type: string

Accessors: GetUrl, SetUrl

Action Detail

DoExecute(params)

Executes a REST service operation, substitutes any of the provided parameter values if necessary.

Parameters:

Name Type Description
params object JavaScript object {"name1": "value1", "name2": "value2" }. Parameter values that should be passed to the web service operation.
Sample code:
SeS("LibraryInformationSystem_Get_BookById").DoExecute({"session_id":sessionId, "book_id":bookId});var book = SeS("LibraryInformationSystem_Get_BookById").GetResponseBodyObject();

Returns:

boolean: 'true' if success, 'false' otherwise.

DoVerify(msg, jsonPath, expectedValue)

Checks that a given part of response equals the expected value.

Parameters:

Name Type Description
msg string Message to write into the report.
jsonPath string Path to the given node in the response object to use as a root for comparison with the expected value.
expectedValue object Expected value.

Returns:

boolean: 'true' if success, 'false' otherwise.