-
Notifications
You must be signed in to change notification settings - Fork 2
Configuring REST Input
This type of inputs allow to create custom REST routes to handle POST requests and also allow to modify the command they send to the platform when read.
There are two possible configurations according to the desired behavior, which are specified using the command
and information
fields:
-
Pass the entire JSON request body
-
Extract information (field values) from the body and pass it
The configuration of these type of inputs also depend on the REST module to which they belong. For the sake of the following examples, we will assume that the owner modules is configured with the following data:
baseURL: "/rest"
port: 4567
As this is a generic POST input, the path or URL where this POST request will come from needs to be specified. This gives the user the option to tailor the REST API to their own use cases.
To configure a URL for a POSTInput
, just pass it in the URL
field. The complete URL, will be defined by the baseURL parameter of the REST Module definition. So if the modules is configured with a baseURL
of "/rest"
and we want to send POST request to the URL /rest/post_test
:
{
"name" : $NAME,"URL": "/post_test","command": $COMMAND,"information": $DATA_TO_EXTRACT
}
For this, the placeholder $body
should be used when defining the command. Given that there is no information to extract from the body then information
should be passed as an empty array.
For example the input :
{"name" : "post1","URL": "/post_test","command": "test $body","information": []}
After a request is made to <IP_ADDRESS>:4567/rest/post_test
with the following body:
{
"name" : "test",
"number" : 1
}
will return the following when read by the platform
test {\"name\":\"test\",\"number\":1}
The input can also be configured to extract field values from the body in order to avoid passing the entire body. In this case, the command is modified accordingly using $
as placeholder for the fields in the request and passing their names in an array in information
Note: Only JSON fields of type String, number or boolean can be extracted
Let's take the same example request from the last section
{
"name" : "test",
"number" : 1
}
But now, configure the POSTInput
to extract both fields name
and number
:
{
"name" : "post1","URL": "/post_test","command": "test $name $number","information": ["name", "number"]
}
Notice that in both
command
andinformation
the names used for the fields are exactly the same as they are in the original request. Only parameters which are defined incommand
andinformation
and have the same name in the request can be extracted!
So, when being read by the platform, this new input will return
test test 1