In Flowgear, a small number of “utility” Nodes deal with two common tasks – preparing payloads for use on a Connector Node and then reading part of a response document out of a Connector Node.
If you’ve worked with Flowgear for any length of time you’ll know that payload preparation is usually done using the Formatter Node while extracting relevant fields out of a response document is usually done with the JSON Match or XML Match Nodes.
An unfortunate consequence of this approach is that a large proportion of the Nodes present on the Workflow design are concerned with these utility-type functions rather than “useful” integration activity.
Here’s an example of these two Nodes being used – the Formatter Node is used to prepare a URL, the JSON Match Node is used to pull out the portion of the response document we’re interested in:
Today we’re introducing a much more succinct way to deal with these two tasks. You’ll end up with significantly fewer steps on the Workflow design while still finding it easy to mentally parse a Workflow you’re coming back to months later.
Here’s the same Workflow using the new methodology:
Payload Templating
You can now add Custom Properties on any Node to have string templates in those properties resolved automatically. Say for example you’re working with Web Request and you need to be able to dynamically set part of the URL. Previously you’d need to use a Formatter as a precursor step to prepare the request headers by resolving in the authorization token and then inject the resolved document into the request headers property.
Now, you can just add a Custom Input Property called “format” then specify a template directly in the Url Property like this:
https://api.ipify.org?format={format}
The Console will also give you intellisense and autocomplete as you type in the names of any Custom Properties that have been added and you can add any number of Custom Properties that can be used on any number of Static Properties containing templates.
Response Evaluation
It’s usually necessary to determine whether a Node invoke failed or succeeded after it completes execution. Most connector Nodes return a document (e.g. JSON) on completion and you’ll need to parse into the document to pick out properties that are of interest for that evaluation.
Once those property values have been picked out, you’ll typically do one of two things – use an If statement to change the process flow based on failure or success or log the failure or success (for example using a Statistic Node).
Now, instead of adding a JSON Match or XML Match as you would previously have needed to don, you can drag a Data Flow Connector from the response document property to the Node that needs one of the properties. Once you’ve created the Data Flow Connector, hover over it to see a formula button. Click the button to provide a JSON Path expression that returns the property of interest.
Additionally, if you place some sample data in the output document property, the Console will provide a treeview that allows you to visually select an element in the hierarchy so the JSON Path expression doesn’t need to be written by hand.
It’s also worth noting that JSON Path allows for inline querying (similar to XPath for XML). Take a look at https://restfulapi.net/json-jsonpath/ for more on how this works.