Skip to content

RESTService

This behavior pattern implements REST service client.

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
Parameter Get/Set single parameter by name. GetParameter SetParameter
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
RequestHeader Get/Set Single HTTP header by name. GetRequestHeader SetRequestHeader
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
ResponseStatusCode HTTP response code GetResponseStatusCode
ResponseStatusText Text version of the response code GetResponseStatusText
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.
DoRemoveParameter Remove one pre-defined parameter.
DoRemoveRequestHeader Remove one pre-defined request header by name.
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

Parameter

Get/Set single parameter by name.

Getter Parameters:

Name Type Description
name string Name of a parameter.

Type: object

Accessors: GetParameter, SetParameter

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

RequestHeader

Get/Set Single HTTP header by name.

Getter Parameters:

Name Type Description
name string HTTP Header name.

Type: object

Accessors: GetRequestHeader, SetRequestHeader

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

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

ResponseStatusCode

HTTP response code

Type: number

Accessors: GetResponseStatusCode

ResponseStatusText

Text version of the response code

Type: string

Accessors: GetResponseStatusText

Url

The URL being used to access the web service

Type: string

Accessors: GetUrl, SetUrl

Action Detail

DoExecute

Executes a REST service operation, substitutes any of the provided parameter values if necessary. Operation fails if HTTP status code is other than 200. If that is an intention, pass ignoreStatus as true. Sample code:

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

Parameters:

Name Type Description
params object JavaScript object {"name1": "value1", "name2": "value2" }. Parameter values that should be passed to the web service operation.
ignoreStatus boolean Don't fail if operation status other than 200, just return the code
Optional, Default: "false".

Returns:

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

DoRemoveParameter

Remove one pre-defined parameter. Requires Rapise 6.6+

DoRemoveParameter(name) 

Parameters:

Name Type Description
name string Parameter name

DoRemoveRequestHeader

Remove one pre-defined request header by name. Requires Rapise 6.6+

DoRemoveRequestHeader(name) 

Parameters:

Name Type Description
name string Header name

DoVerify

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

DoVerify(msg, jsonPath, expectedValue) 

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.