EXTERNAL operator
The EXTERNAL operator creates an action that implements accessing to an external system.
Syntax
EXTERNAL externalCall [PARAMS paramExpr1, ..., paramExprN] [TO propertyId1, ..., propertyIdM]
externalCall - an external call defined by one of the following syntaxes:
HTTP [CLIENT] [requestType] connectionStrExpr httpOption1 ... httpOptionN
TCP [CLIENT] connectionStrExpr
UDP [CLIENT] connectionStrExpr
SQL connectionStrExpr EXEC execStrExpr
LSF connectionStrExpr lsfExecType execStrExpr
DBF connectionStrExpr APPEND [CHARSET charsetLiteral]
The HTTP options (in any order, separated by spaces or line feeds) are:
BODYURL bodyStrExpr
BODYPARAMNAMES bodyParamNameExpr1, ..., bodyParamNameExprK
BODYPARAMHEADERS bodyParamHeadersPropertyId1, ..., bodyParamHeadersPropertyIdK
HEADERS headersPropertyId
COOKIES cookiesPropertyId
HEADERSTO headersToPropertyId
COOKIESTO cookiesToPropertyId
NOENCODE
Description
The EXTERNAL operator creates an action that performs a single call to an external system. The call type (HTTP, SQL, LSF, TCP, UDP, DBF) selects the protocol or interface used. Each type accepts its own clauses on top of the shared PARAMS and TO lists.
Parameters
-
HTTP,TCP,UDP,SQL,LSF,DBFKeywords. Select the type of external call. See Access to an external system for the semantics of each.
-
requestTypeKeyword. Defines the method of the HTTP request:
POSTGETPUTDELETEPATCH
The default value is
POST. -
CLIENTKeyword. Runs the call on the user's client. Without
CLIENTthe call runs on the application server. -
APPENDRequired keyword in the
DBFcall syntax. -
charsetLiteralString literal with the charset used for the
.dbffile. Defaults toUTF-8. -
connectionStrExprExpression.
HTTP: http request string.TCP/UDP:host:portof the target socket.SQL: DBMS connection string.LSF: URL of an lsFusion application or web server.DBF: path to the.dbffile. -
bodyStrExprExpression. BODY string with
$Nparameter substitutions. All parameters remaining after URL substitution must be consumed inside this string, otherwise the call fails. ForGETBODYURLhas no effect and any remaining parameters are silently dropped. -
bodyParamNameExpr1, ..., bodyParamNameExprKList of expressions. Each evaluates to a BODY part name in the form
'name'or'name;filename'(the part after;sets the multipart file name). WithoutBODYPARAMNAMESBODY parts get default auto-namesparam0,param1, ... (file parts without an explicit filename similarly getfile0,file1, ...). -
bodyParamHeadersPropertyId1, ..., bodyParamHeadersPropertyIdKList of property IDs. Each property has one string-class parameter (the header name) and a string-class value (the header value). Without
BODYPARAMHEADERSno extra headers are attached to BODY parts. -
headersPropertyId,headersToPropertyIdProperty IDs. Each property has one string-class parameter (the header name) and a string-class value (the header value). Without
HEADERSno custom request headers are sent, and withoutHEADERSTOresponse headers are not captured. -
cookiesPropertyId,cookiesToPropertyIdProperty IDs. Each property has one string-class parameter (the cookie name) and a string-class value (the cookie value). Without
COOKIESno custom cookies are sent, and withoutCOOKIESTOcookies are not captured. -
NOENCODEKeyword. Disables URL pre-encoding of the text of the connection string and the
BODYURLstring itself (parameter values substituted via$Nare still URL-encoded separately). WithoutNOENCODEthis text is URL-encoded before sending. -
lsfExecTypeKeyword. Specifies the way of defining the action:
EXEC– the name of the action is specified.EVAL– the code of the action is specified in the lsFusion language. It is assumed that this code contains a declaration of an action namedrun. This is the action that will be called.EVAL ACTION– the action code in the lsFusion language is specified. To access a parameter, the special character$and the parameter number (starting from1) are used.
-
execStrExprExpression.
SQL: SQL command(s) — an expression ending in.sqlis treated as a path to a classpath resource whose contents are used as the command.LSF: action name or code, perlsfExecType. -
paramExpr1, ..., paramExprNList of expressions whose values will be used as the call parameters.
-
propertyId1, ..., propertyIdMList of property IDs (without parameters) to which the results will be written.
Examples
externalHTTP() {
// HTTP method + TO result
EXTERNAL HTTP GET 'https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg' TO exportFile;
// BODYURL: second and third parameters are consumed into a url-encoded BODY via $N
EXTERNAL HTTP 'http://tryonline.lsfusion.org/exec?action=doSomething&someprm=$1'
BODYURL 'otherprm=$2&andonemore=$3' PARAMS 1, 2, '3';
// BODYPARAMNAMES with 'name;filename' + manual Content-Type via HEADERS
LOCAL headers = TEXT(STRING[100]);
headers('Content-Type') <- 'multipart/form-data; charset=UTF-8';
EXTERNAL HTTP POST 'https://api.example/upload'
BODYPARAMNAMES 'document;report.pdf'
HEADERS headers
PARAMS exportFile();
// HEADERSTO / COOKIESTO capture response headers and cookies
LOCAL respHeaders = TEXT(STRING[100]);
LOCAL respCookies = TEXT(STRING[100]);
EXTERNAL HTTP GET 'https://api.example/login'
HEADERSTO respHeaders
COOKIESTO respCookies
TO exportFile;
}
externalTCP() {
EXTERNAL TCP 'example.com:9100' PARAMS RAWFILE('payload');
MESSAGE STRING(responseTcp());
}
externalSQL () {
// inline SQL command with a TABLE parameter loaded into a temporary table
EXPORT TABLE FROM bc=barcode(Article a) WHERE name(a) LIKE '%Meat%';
EXTERNAL SQL 'jdbc:mysql://$1/test?user=root&password='
EXEC 'select price AS pc, articles.barcode AS brc from $2 x JOIN articles ON x.bc=articles.barcode'
PARAMS 'localhost', exportFile()
TO exportFile;
}
externalLSF() {
EXTERNAL LSF 'http://localhost:7651' EXEC 'System.testAction[]';
}
externalDBF() {
EXPORT TABLE FROM bc=barcode(Article a), nm=name(a);
EXTERNAL DBF '/tmp/articles.dbf' APPEND CHARSET 'CP866' PARAMS exportFile();
}