How to send a request to Totum by path?
For example, you have a third-party server that needs to pass parameters and get a response from Totum.
The best solution for this is remotes — built-in API microservices in Totum.
The simplest option is to create a row in the table System Tables —> Main —> API —> Remotes.
Set name + remotes_user + code:
=: selectRowList(table: 'users'; field: 'login'; field: 'fio')
In return, set the option to json and enable on_off.
Now, if we open https://HOST.TOTUM/Remotes/NAME_ACTION in the browser, we will see a list of all system users in json format.
Is it possible to write a handler and an information collector on a totum code?
Yes, the code in code in remotes is written specifically in totum-code.
How can I pass data in such a query and how do I get it in the totum code?
In a request to Totum, GET or POST parameters can be passed.
Within the code in code, the request parameters can be obtained through variables:
$#get — row from the variables passed in GET.
$#post — row from the variables passed in POST when using application/x-www-form-urlencoded or multipart/form-data in the Content-Type header of the HTTP request.
$#input — string or null — raw data from the request body when passed in POST as raw-data.
$#headers — row from the HTTP request headers.
Note that if the parameters are passed marked in GET or POST (not in raw-data), they will arrive in Totum code already in Totum format.
So if your request to the remote contains POST with parameters key = zzGhdy and name = Alexey, to find such a record in the table by key:
=: select(table: 'table'; field: 'summ'; where: 'key' = $#post[key])
If the request came in raw-data and you received it using $#input, it will just be a string that you will need to parse into parts.
What are the coding options for the answer?
success/error — returns success or error if there were errors during execution. The error text is not displayed.
json — the script's response is converted to JSON. If an error occurs, {"error":"Error text"} is returned.
row — the script's response is returned in the response body without processing.
headers + body — the script's response is expected to contain a row with keys headers — sent as HTTP response headers and body — output in the response body.
Is it possible to test remote without sending a request?
Yes, the remotes table has 4 fields: get, post, input, data and a check_remote button.
get, post, input, and data correspond to variables. We'll talk about data a bit later.
When the code is executed by pressing the check_remote button, it will run under the user who presses the button, not under the remotes_user user.
Is it possible to perform an action in the totum when such a request is received?
Of course. Code is an action code. For example, if we want to create a string and write the incoming POST into the data field:
=: insert(table: 'table'; field: 'data' = $#post)
From which user will the change record be made in this case when the logs are enabled?
From the user specified in remotes_user.