Rest
- Last UpdatedFeb 19, 2025
- 5 minute read
The Rest node performs a rest call to specific rest servers to perform a set of functions.
Platform support
This element is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, and XR-Portable Androi. It is not supported on XR-Portable WASM platform.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Full support |
Full support |
Full support |
No support |
|
|
|
|
|
|
Customizing the Rest HTTP request
The Rest node offers a way to customize the request sent to the designed URI.
Headers
The headers field can be used to specify any header parameter: standard or server specific. Note that no default header is set by the system, so it’s the user responsibility to set all and only the required headers.
Content
The body and bodyEncoding fields are used to define the request body.
-
When the encoding is set to stringContent, the body can be set to any value.
-
When the encoding is set to formUrlEncodedContent, the body must be set to DString content.
Selecting Rest HTTP Method
The Rest node supports multiple http methods: GET, POST, PUT, PATCH, and DELETE to allow the interface of a pure REST API.
-
GET does not send the body content, so eventual parameters need to be included in URI as querystring.
-
DELETE does not send body content.
Exploring the Rest HTTP response
When the REST call is performed by raising sendRequest, the error state goes to undefined. Then, depending on the completion of the query it falls to ok or error.
The Rest response includes multiple fields:
-
result: The response content. If the rest call state is in error state, the result contains the error message.
-
responseHeaders: The headers associated to the response.
-
statusCode: The response http status. This is set to -1 when an error occurs while executing the rest call.
Certificates and authentication
Rest node supports certificates for https. However, there is a special skipServerCertificate flag that allows the method to run without checking for a certificate. You can set authentication parameters through the corresponding parameter to be shipped into the http request.
Cyber Security Note: Before using the skipServerCertificate parameter, be fully aware of the security repercussions of sending authentication and/or other sensitive data in any clear-text communication channel. Any malicious users sniffing the network traffic can read the data, they can impersonate your application and perform calls with many possible parameters, and—depending on your queries— could even inject or dump data into and from your database.
Cyber Security Note: Whether you are using HTTPS or HTTP, also be aware that any user with write access to the bridge.xml file in your deployment could modify your query definitions. This could lead to disclosure of confidential data, loss of integrity of the database and loss of availability of the solution. Make sure you grant write access to the bridge.xml file with full awareness of the security limitations they imply and only for cases where you consider them acceptable.
Using Rest with XR Bridge
The http rest server of bridge can perform calls to db channel and perform execution of db <query/> and <nonquery/>.
The syntax is the following:
http://serverIP:serverPort/executeFunction?channel=DBchannelName&function=queryOrNonQueryName
If the <query/> or <nonquery/> has a dynamic parameter (%paramA%, %paramB%..) they can be populated when triggering the call by passing them in a dictionary ({paramA=value}{paramB=value}.
|
Parameters |
Description |
|---|---|
|
DBchannelName |
The name of channel of db type defined in the bridge.xml. |
|
queryOrNonQueryName |
The name of the query (or nonquery) to execute. |
|
serverIP |
The bridge IP address. |
|
serverPort |
The bridge rest port as defined in bridge.xml. |
Code example
This is a code example for the Rest node.
<Rest name="rest" />
<Coroutine name="restQuery" >
<set name="rest.uri" value="[@def:tokenEndpoint]" />
<set name="rest.method" value="POST" />
<set name="rest.bodyEncoding" value="formUrlEncodedContent" />
<set name="rest.body" value="{client_id=[@def:clientId]}{client_secret=[@def:clientSecret]}{grant_type=client_credentials}" />
<log text="Sending request to:[@rest.uri]" />
<log text="Using method to:[@rest.method]" />
<log text="Body Encoding:[@rest.bodyEncoding]" />
<log text="Body Content:[@rest.body]" />
<log text="Overriden headers:[@rest.headers]" />
<set name="rest.sendRequest" />
<log text="-------" />
<wait condition="[@restQuery.timeFromWait]<0.1" />
<wait condition="[@rest.error]!=ok" />
<log text="Result:[@rest.result]" />
</Coroutine>
Rest fields
These are the fields for Rest node. Only the node-specific fields are indicated, not fields obtained by inheritance.
Field inheritance: NodeBase > Rest
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
authentication |
sstring |
Optional |
Empty |
Sets the authentication user and password into the rest request. It expects to receive a string in the format: user:pwd. |
|
body |
sstring |
Optional |
formUrlEncodedContent |
This is the content of the request. It can be set to anything when the bodyEncoding is set to stringContent. It must be set to a DString content when using it to pass form params with formUrlEncodedContent. |
|
bodyEncoding |
senum |
Optional |
Empty |
Specifies the body content encoding. When set to formUrlEncodedContent, the body must have a DString content. |
|
call |
sstring |
Optional |
Empty |
Triggers the rest call. Parameters can be added with a dictionary syntax. The use of this field is deprecated. Content should be set to body and use sendRequest to trigger the call. |
|
callFinished |
sevent |
Optional |
Empty |
Raised when the call enters both ok or error state. |
|
error |
senum |
Read only |
Internally calculated |
Populated with rest call state: undefined, ok, or error. |
|
headers |
dstring |
Optional |
Empty |
This dictionary can be used to set/override http request headers. |
|
method |
senum |
Optional |
POST |
Specifies the REST method to use. Values are GET, POST, PUT, PATCH, and DELETE. |
|
responseHeaders |
dstring |
Read only |
Internally calculated |
Headers associated to the rest response. |
|
result |
sstring |
Read only |
Internally calculated |
When Error parameter is set to OK, contains result of the Rest call. When Error parameter is set to Error, contains an error message. |
|
sendRequest |
sevent |
Optional |
Empty |
Triggers the http rest call. |
|
skipServerCertificate |
sbool |
Optional |
false |
Used to skip the certificate check on https connections. |
|
statusCode |
sint |
Read only |
Empty |
Http response code. In case of errors in the call, the execution the value is set to -1. |
|
uri |
sstring |
Optional |
Empty |
The complete URI query string. |