- Choreo Expression Syntax
- Supported Literals
- Accessing Variables
- Supported Operators
- HTTP request related operations
A powerful expression syntax based on Ballerina language is used in the Choreo portal to efficiently provide inputs to different fields in a contextual manner. This document presents you the common expressions that can be used while developing Choreo applications.
A string is simply a sequence of characters. Double quotes (") character is used to mark the boundary between starting and ending characters.
-
"Colombo"
-
"12345"
-
"Ballerina is a programming language intended for network distributed applications"
This type can be used to give numbers as an input to an expression supported field. Only numerical characters without any delimiters are used to define an integer. You have the option to use +
or -
characters in the front to indicate the sign.
-
1234
-
-10
-
+2020
A number with a decimal point falls under this data type. You have the option to use +
or -
characters in the front to indicate the sign.
-
0.3353
-
2044.24
-
-8593.992
-
+950.930
-
10.0
This data type has one of two possible values, denoted true and false.
-
true
-
false
Variables are used to keep values in memory to be used at a later time. In an expression syntax supported input field, you can refer to these variables directly by using the name of the variable.
-
VariableName
The +
operator can be used to do string concatenations. The string value can come from a string literal or a variable.
- Concatenating two string literals
"Hello " + "world!"
- Concatenating a string literal and a variable
"Hi " + nameVar
- Concatenating two string variables
firstNameString + lastNameString
The +
operator can be used for number addition. The number values can come from a literal or a variable.
- Concatenating two integer literals
10 + 20
- Concatenating two decimal literals
0.56 + 1.84
- Concatenating a literal and a variable
100 + nameVariable
- Concatenating two variables
firstNumber + secondNumber
The -
operator can be used for number subtraction. The number values can come from a literal or a variable.
- Subtracting two integer literals
10 - 20
- Subtracting two decimal literals
0.56 - 1.84
- Subtracting a literal and a variable
100 - nameVariable
- Subtracting two variables
firstNumber - secondNumber
The /
operator can be used for number division. The number values can come from a literal or a variable.
- Division between two integer literals
10 / 20
- Division between two decimal literals
0.56 / 1.84
- Division between a literal and a variable
100 / nameVariable
- Division between two variables
firstNumber - secondNumber
The *
operator can be used for number multiplication. The number values can come from a literal or a variable.
- Multiplying two integer literals
10 * 20
- Multiplying two decimal literals
0.56 * 1.84
- Multiplying a literal and a variable
100 * nameVariable
- Multiplying two variables
firstNumber * secondNumber
The %
operator can be used to get the remainder of a division. The number values can come from a literal or a variable.
- Modulus of two integer literals
10 % 4
- Modulus of a literal and a variable
100 % nameVariable
- Modulus of two variables
firstNumber % secondNumber
Basic types in the Ballerina language are strings, integers, decimal numbers, and booleans. Values of these types can be compared using the ==
binary operator. The values can come from a literal or a variable. Similarly !=
operator is used to check the inequality. Please note that the resulting value is always of type boolean from these operators.
- Equality of two integer literals
10 == 4
- Equality of two string literals
"hi" == "hi"
- Equality of a literal and a variable
100 == expectedValueVariable
- Equality of two variables
firstNumber == secondNumber
- Inequality of two variables. The following will return true when the value of two variables are different.
firstNumber != secondNumber
The is
operator can be used to assert the type of a variable.
- Checking whether the variable is of type JSON
payload is json
Following comparison operators are available in the expression editor for numeric value comparisons
<
(less than)>
(greater than)<=
(less than or equal to)>=
(greater than or equal to)
- Check a variable’s value is greater than 10
myVar > 10
- Comparing two variables
myProperty <= limit
All the HTTP related service applications created in Choreo has a variable called req
(of type http:Request
) which the developers can use to query information related to the HTTP request. Following is a list of common use cases that an integration application developer would need to develop Choreo applications.
A typical HTTP request contains many headers. Some of the headers are standard and some are custom. In an expression enabled input field the req
variables getHeader
function can be used to read a specific header value.
- Reading the value of Access-Control-Allow-Origin HTTP header
req.getHeader("Access-Control-Allow-Origin")
- Using a value stored in a variable as the header name. Please note the omission of the double-quotes.
req.getHeader(headerName)
Applications sometimes need to check the availability of a header before proceeding to something like reading the header value. The hasHeader
function in the req object can be used for this purpose.
- Checking whether the "content-length" property is available as a header
req.hasHeader("content-length")
- Using a value stored in a variable as the query parameter name. Please note the omission of the double-quotes.
req.hasHeader(myCustomeHeader)
JSON is a common content type used for HTTP communication. The req variable’s getJsonPayload
function can be used to read the JSON payload sent with the HTTP request. Please note that the getJsonPayload
function’s return type is json|ClientError
.
- Reading the JSON Payload of the HTTP request
req.getJsonPayload()
Sometimes, content is sent as a string (plain text) with the HTTP request. The req variable’s getTextPayload
function can be used to read the Text payload sent with the HTTP request. Please note that the getTextPayload
function’s return type is string|ClientError
.
- Reading the Text Payload of the HTTP request
req.getTextPayload()
Query parameters are used in an HTTP request to send additional inputs to consider when processing the request. The req variable’s getQueryParamValue
function can be used to read the passed query parameter.
- Reading the query parameter named "category"
req.getQueryParamValue("category")
- Using a value stored in a variable as the query parameter name. Please note the omission of the double-quotes.
req.getQueryParamValue(queryParamName)
HTTP Cookies are used to keep stateful information against a client. The req variable’s getCookies
function can be used to read cookies present in the request as an array.
- Reading all the cookies available in the request
req.getCookies()