An OL Connect web flow in Node-RED
This topic explains which nodes and files are used in a typical OL Connect web flow in Node-RED.
Tip: Example web flows are provided by OL Connect Automate, once installed. The examples appear in the flows folder in the Import dialog in Node-RED which allows you to import an example flow into a new or existing flow; see Importing and Exporting Flows in the Node-RED documentation. Instructions are given in the Comment node.
Alternatively, an easy way to get the files that the typical OL Connect web flow needs, is to create a Sample Project (see Sample Project: Serving a Web Page. ). You would use all files except the Workflow configuration file.
The structure of an OL Connect web flow
In an OL Connect web flow only one plugin is essential: the html content plugin.
The html content node creates a set of web pages, using the Web context in a Connect template, and stores them in the File Store or serves it.
If the template doesn't need any data, set msg.payload
to an empty JSON string: {}
.
If the template should be merged with data, the data can be the output of another node. Nodes that output data that can be used by the html content node are:
-
An HTTP in node. It will pass any query parameters via the payload. Query parameters are key/value pairs attached to the end of an URL. The first parameter is appended to the URL using a ? (question mark). If there are multiple parameters, an & (ampersand) is added in between each. Example: http://localhost:1881/hello?first=Peter. Note that in order to use them as data, the parameter names must match field names in the template's data model.
The flow should end with a http response node which serves the HTML output. - An OL Connect data mapping node which retrieves data from the job file (such as the request XML). In addition to creating records in the Connect database, this task can output the (IDs of the) records.
- An OL Connect data get node which retrieves an existing record set from the Connect database.
- A standard create file node that creates a JSON file.
- Etc.
Which node or nodes fit best, depends on where the data come from.
The html content node accepts runtime parameters. These can be passed via the parameters
property of the msg
object which is passed between nodes. For example, a runtime parameter named brandId would be passed via msg.parameters.brandId
.
Tip: Use a change node or function node to set a property. See also: Node-RED: nodes and common techniques.
Files used in an OL Connect web flow
Before creating the web flow in the editor of Node-RED you will need to create:
- A template with a Web context. (See Creating a template.)
- If the HTML file should contain variable data, you may need to create a data mapping configuration (see Creating a new data mapping configuration). If the input is going to be JSON data, you could add them to the design using a JSON file (see Adding JSON sample data).
Note that before templates and data mapping configurations can be used in a flow, they must be sent to the OL Connect server separately. This can be done from the Designer (see Sending files to Connect Server or to another server) or in a startup flow (see OL Connect startup flow).