EchoScript Extension
When you need to implement complex logic, you can write EchoScript extensions in ANY programming language, such as JavaScript, Python, Java, Go, etc.
EchoScript uses function exec
to run extensions in a very convenient way.
You can use function is_error
to check whether the value is error
or not.
The return value of exec
depends on the output of the command.
cmd output | cmd exit code | exec return value |
---|---|---|
json {...} | 0 | map |
not json {...} | 0 | string |
any | != 0 | error |
The name
argument is the command
in $PATH
, or absolute file path to the command
.
The args
argument type can be string|file|map|array
.
The map|array
arguments are transformed to json file
automatically.
args argument type | actual command argument |
---|---|
string | string |
map | json file path |
array | json file path |
file | file path |
Python
Example 1
Use python
to generate uuid
and base64
. Create a Map Rule with following settings:
MapLocal, GET, Equals, Enabled ✅
URL:https://demo.echolabx.com/
Content of python file ~/gen_uuid_base64.py
:
Visit the URL https://demo.echolabx.com/ again, the new response body data:
You can see exec
log on Tab Log
.
Example 2
When you want to pass more information to exec
command, you can use map
as argument.
Create a Map Rule with following settings:
MapLocal, GET, Equals, Enabled ✅
URL:https://demo.echolabx.com/
exec
automatically transform map
argument to a file with to_file
function,
the command can read the file and decode the content as json
.
Content of python file ~/use_json.py
. It loads the first argument as a json file
.
Visit the URL again, the new response body data:
You can see exec
log on Tab Log
.
JavaScript
You can write extensions in JavaScript
with Node.js
.
Create an example Map Rule with following settings:
MapLocal, GET, Equals, Enabled ✅
URL:https://demo.echolabx.com/
Content of JavaScript file ~/use_json.js
. It loads the second argument as a json file
.
Visit the URL again, the new response body data:
You can see exec
log on Tab Log
.