Web request
Technical block
Technical blocks allow the creation of more complex and innovative scenarios.
They generally have no visual impact, and focus on the logic of your scenario execution.
Behaviour
The Web Request block allows to establish a communication between a VTS scenario and a web service, thanks to Web APIs:
- The URL, GET parameters, POST parameters, and timeout can be configured.
- The API is called when the block is triggered during a scenario, and the execution of the graph is paused until the web service has responded.
- The API response is received as a variable. This variable can then be used in Variables and Conditions blocks, in order to create scenaristic branches depending on the response of the web service.
- The first output is triggered if the communication went well.
- The second output is triggered if communication could not be established, or during a timeout.
Although it can be used without variables, the interest of this block lies in particular in the sending of variable parameters, and in the exploitation of the response of the web service, which is only possible by using variables.
1. The Web Request block is a tool for developers. It requires knowledge in web programming to be used.
2. Virtual Training Suite does not provide a specific web service to connect to with the Web Request block. This block can only be used if you have a web service of your own, and for which you want to establish communication with your VTS scenario.
Examples of uses:
- Connect your module on VTS Player to an LMS with public APIs.
- Create a multiplayer module with regular data synchronization (every X seconds, between each scene, etc.) of the game on a web server.
- Upload usage statistics on a customized web platform.
- Etc.
Parameters
Url
Allows you to define the URL of the API to call.
- It is possible to insert variables, with the {variable} syntax, but this is generally not useful because the GET and POST parameters can be specifically configured (see below).
- The URL itself can be a variable if your situation requires it. For example: {api_url}
GET parameters
Define here the list of GET parameters to send to your API: the name on the left, the value on the right.
The name and value can be defined using variables.
For example, as the block is configured in the image above, the value of the last 3 GET parameters is defined using variables.
POST parameters
Define here the list of POST parameters to send to your API: the name on the left, the value on the right. As for GET parameters: the name and value can be defeined with variables.
Raw
on The list of POST parameters becomes a single field, allowing you to insert a single text value. For example a complex XML, containing variable values. Enable this option only if necessary. off The POST parameters are defined by a list of key-value pairs.
Timeout
Définissez ici le temps maximum que la requête web doit attendre avant de recevoir une réponse de la part du serveur web. Votre scénario sera donc Define here the maximum time the web request should wait before receiving a response from the web server. Your scenario will be paused for this maximum time.
If the time is reached, the 2nd output of the Web Request block will be triggered.
Request result
Specify here the name of the variable in which the text result of the query should be stored.
This result can be used in the Variables or Conditions blocks in the rest of your scenario.
Some functions can be very useful to exploit the result, in particular:
- fromJson(result) Allows to deserialize the contents of the variable into a JSON structure: dictionaries, lists, flag, text, integer, decimal. These 6 types of variables are properly managed by the Virtual Training Suite variables system. All the most common functions to manipulate them exist.
- regexMatch(result, regex) To check that the reponse is valid according to a given regular expression.
- extractText(result, regex, 0) To extract a specific part of the response.
- toInteger(result) To convert the response (text) to an integer.
- Etc.
- ${ child.title }