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 |
ProxyHost | Proxy host name. | GetProxyHost | SetProxyHost |
ProxyPort | Proxy port number. | GetProxyPort | SetProxyPort |
ProxyPwd | Proxy password. | GetProxyPwd | SetProxyPwd |
ProxyUser | Proxy user name. | GetProxyUser | SetProxyUser |
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. |
DoSetProxy | Sets proxy for this request. |
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
value = SeS('SomeRESTService').GetCredential()
SeS('SomeRESTService').SetCredential(value, value2)
Method¶
The HTTP Method being used for the request (GET, POST, etc.)
Type: string
Accessors: GetMethod, SetMethod
value = SeS('SomeRESTService').GetMethod()
SeS('SomeRESTService').SetMethod(value)
Name¶
The name of the request operation
Type: string
Accessors: GetName
value = SeS('SomeRESTService').GetName()
Parameter¶
Get/Set single parameter by name.
Getter Parameters:
Name | Type | Description |
---|---|---|
name | string | Name of a parameter. |
Type: object
Accessors: GetParameter, SetParameter
value = SeS('SomeRESTService').GetParameter(/**string*/name)
SeS('SomeRESTService').SetParameter(/**string*/name, /**string*/value)
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
value = SeS('SomeRESTService').GetParameters()
SeS('SomeRESTService').SetParameters(name, value)
ProxyHost¶
Proxy host name. Requires Rapise 8.1+.
Type: string
Accessors: GetProxyHost, SetProxyHost
value = SeS('SomeRESTService').GetProxyHost()
SeS('SomeRESTService').SetProxyHost(value)
ProxyPort¶
Proxy port number. Requires Rapise 8.1+.
Type: string
Accessors: GetProxyPort, SetProxyPort
value = SeS('SomeRESTService').GetProxyPort()
SeS('SomeRESTService').SetProxyPort(value)
ProxyPwd¶
Proxy password. Requires Rapise 8.1+.
Type: string
Accessors: GetProxyPwd, SetProxyPwd
value = SeS('SomeRESTService').GetProxyPwd()
SeS('SomeRESTService').SetProxyPwd(value)
ProxyUser¶
Proxy user name. Requires Rapise 8.1+.
Type: string
Accessors: GetProxyUser, SetProxyUser
value = SeS('SomeRESTService').GetProxyUser()
SeS('SomeRESTService').SetProxyUser(value)
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
value = SeS('SomeRESTService').GetRequestBodyObject()
SeS('SomeRESTService').SetRequestBodyObject(value)
RequestBodyText¶
The body of the HTTP request in raw text format
Type: string
Accessors: GetRequestBodyText, SetRequestBodyText
value = SeS('SomeRESTService').GetRequestBodyText()
SeS('SomeRESTService').SetRequestBodyText(value)
RequestHeader¶
Get/Set Single HTTP header by name.
Getter Parameters:
Name | Type | Description |
---|---|---|
name | string | HTTP Header name. |
Type: object
Accessors: GetRequestHeader, SetRequestHeader
value = SeS('SomeRESTService').GetRequestHeader(/**string*/name)
SeS('SomeRESTService').SetRequestHeader(/**string*/name, /**string*/value)
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
value = SeS('SomeRESTService').GetRequestHeaders()
SeS('SomeRESTService').SetRequestHeaders(value, optValueVal)
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
value = SeS('SomeRESTService').GetResponseBodyObject(jsonPath, info)
ResponseBodyText¶
The body of the HTTP response in raw text format
Type: string
Accessors: GetResponseBodyText
value = SeS('SomeRESTService').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
value = SeS('SomeRESTService').GetResponseHeaders()
ResponseIsErrorStatus¶
Returns 'true 'if an HTTP error code came back from the web service
Type: boolean
Accessors: GetResponseIsErrorStatus
value = SeS('SomeRESTService').GetResponseIsErrorStatus()
ResponseStatusCode¶
HTTP response code
Type: number
Accessors: GetResponseStatusCode
value = SeS('SomeRESTService').GetResponseStatusCode()
ResponseStatusText¶
Text version of the response code
Type: string
Accessors: GetResponseStatusText
value = SeS('SomeRESTService').GetResponseStatusText()
Url¶
The URL being used to access the web service
Type: string
Accessors: GetUrl, SetUrl
value = SeS('SomeRESTService').GetUrl()
SeS('SomeRESTService').SetUrl(value)
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();
SeS('SomeRESTService').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+
SeS('SomeRESTService').DoRemoveParameter(name)
Parameters:
Name | Type | Description |
---|---|---|
name | string | Parameter name |
DoRemoveRequestHeader¶
Remove one pre-defined request header by name. Requires Rapise 6.6+
SeS('SomeRESTService').DoRemoveRequestHeader(name)
Parameters:
Name | Type | Description |
---|---|---|
name | string | Header name |
DoSetProxy¶
Sets proxy for this request. Requires Rapise 8.1+.
SeS('SomeRESTService').DoSetProxy(host, port, user, pwd)
Parameters:
Name | Type | Description |
---|---|---|
host | string | Proxy host name or IP address. |
port | string | Proxy port. |
user | string | Proxy user name. Optional. |
pwd | string | Proxy password. Optional. |
DoVerify¶
Checks that a given part of response equals the expected value.
SeS('SomeRESTService').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.