api:script

Version 22.0.8500


api:script

Version 22.0.8500


The api:script keyword can be used to create script blocks that respond to REST methods.

Parameters

  • method: The HTTP method (GET, POST, PUT/PATCH/MERGE, or and DELETE) used to invoke the script. Specify multiple methods in a comma-separated list. This can be used to create REST-like services in APIScript.
  • language: The programming language used to program the script. For example, python or js.

Control Attributes

None

Examples

Below is the script that defines the GetTransmissionDetails service. The script will be executed only when GetTransmissionDetails is accessed using the POST method. The input parameters are defined in the body of the HTTP request.

<api:script xmlns:api="http://www.arcesb.com/ns/APIScript/2">
  
  <api:restrict user="admin" role="Administrators"/>
  
  <api:info title="GetTransmissionDetails" description="Retrieves the transmission details of the application.">
    <input name="PortId"          desc="The id of the port." required="true"/>
    <input name="MessageId"       desc="The message Id." required="true"/>
    <input name="Direction"       desc="The direction of the transmission." values="Incoming,Outgoing" required="true"/>
    <output name="LogTimeCreated" desc="The time the log file was created."/>
    <output name="LogType"        desc="The type of the log file." />
    <output name="LogFile"        desc="The name of the log file." />
    <output name="LogPath"        desc="The path of the log file." />
  </api:info>

  <api:script method="POST">
    <api:push op="portGetTransmissionDetails" />
  </api:script>
</api:script>

The next examples show how to use the language parameter to convert a script originally written in APIScript to another language (in this case, Python). Here is a short script that lists *.rst files:

<api:set attr="mask" value="*.rst"/>
<api:call op="fileListDir">
    <api:push/>
</api:call>

Here is the same script written in Python, where the language is established by the language parameter:

<api:script language="python">
  input = {"mask":"*.rst"}
  rsb.call("fileListDir",input)
</api:script>