Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Configuring REST Input

juan-castrillon edited this page Feb 1, 2021 · 1 revision

Configuring POSTInput instances

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:

  1. Pass the entire JSON request body

  2. 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

Configuring the URL

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
}

Behavior 1: Passing the entire body

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}

Behavior 2: Extracting information

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 and information the names used for the fields are exactly the same as they are in the original request. Only parameters which are defined in command and information 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
Clone this wiki locally