Components Data

Data (objects) available in the flow.

Using the visual service builder is very simple as you visually build the flow and the logic of the API. Let's make sure we understand how the flow works:

  • Components are executed in order they are placed on the flow.
  • Every component has inputs and outputs. For example, output from one component can be used as input for another component.
  • The Mapping component can be used to map data any components data to customer variables.
  • As you move in the flow, there are a number of built-in objects that are always available. These objects can be accessed in places along the service flow. The following section describes these objects.

API Express defines the following pre-built objects:

BODY

Contains the output body from previous component.

The simplest way to see how this works is to use the Script component.

Create a very simple flow that consists of: Start > Script > End. For the Start component, set its Request Body to

{"component":"start", "data":"icecream is delicious"}

Inside the Script component, set its code to:

result = BODY;

Now click the Run Script button. You should see the following output:

{
    "component": "start",
    "data": "icecream is delicious"
}

For the Script component, Start is its previous component and thus the BODY objects display the body from the Start component.

SESSION

An object that contains authentication session data.This will be empty if the project is not secured.

USER_NAME

The name of the authenticated user. This will be null if the project is not secured.

PARAMS

The object that contains parameters is initially passed by the user and other information provided by API Express.

PATH

An object contains all parameters passed as PATH PARAMETERS.

To display the content of this object, use the Script component again (as in the example above). In the Start component, after the name, add at least one path parameter. For example: myservice/{param1}/{param2}.

For the Script component, set its code to:

result = PARAMS.PATH;

When you test the Script component, the output will be:

{
    "param1": "",
    "param2": ""
}

QUERY

An object contains all parameters passed as QUERY PARAMETERS.

Testing the query parameters can be done in the same way. For the Start component, create at least one query parameter. For example, queryparam1 and queryparam2.

Using the Script component, sets the script code to:

result = PARAMS.QUERY;

When you test the Script component, the result will be:

{
    "queryparam1": "",
    "queryparam2": ""
}

HEADER

An object contains all parameters passed as HEADER PARAMETERS.

You can display the header params in the say way as path and query parameters. The actual code to display the header parameters is:

result = PARAMS.HEADER;

BODY

Contains a service request body (if POST or PUT methods are used).

The PARAMS.BODY is different from BODY object.

  • BODY - contains data from the previous component.
  • PARAMS.BODY - contains data from the Start component (from Request Body section)

Using the example from BODY section, modify the flow like this: Start > Script (new) > Script (original) > End.

In the new Script component, set the code to:

result = {"topping1":"chocolate", "topping2":"caramel"};

and Run script to set the component output.

Open the second Script component and set its code to:

result = {"start":PARAMS.BODY, "previous":BODY};

When you test the script, you should get the following response:

{
    "start": {
        "component": "start",
        "data": "icecream is delicious"
    },
    "previous": {
        "topping1": "chocolate",
        "topping2": "caramel"
    }
}

We hope this helps you understand the difference between the two objects.

KEYS

When a using a service such as REST, it is common to set a default value that rarely changes. For example, the service API key. Using API Express you can use the Service keys option to store these values.

📘

Default Values

Use the Service keys to store default service values such as API keys, names, URL and anything that's rarely changes.

The Service key page is available from the main API Express project page.

The page has a simple key-value editor. Let's say you want to add an API key value. You can enter something like this:

Key nameKey valueKey description
apiKey9eb45e221bbeabc9API key for my favorite service.

Now you can set any service parameter to this value. This API key will be referenced via PARAMS.KEYS.apiKey. You can create any number of such keys or default values.