Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
What is a HTTP Action?
HTTP actions performs HTTP(S) requests to external APIs and returns the response.
A HTTP action has two outputs. One input request will generate one output record, which will be sent on either the out or error output. A HTTP request will be triggered for each input record and generate one output record.
The response from the server (headers and body) will be treated as the result record, with the input attributes added as passthrough fields.
URL: A template the computes to the URL of the request (including protocol).
Creating HTTP Actions
- Click and drag the
icon from the toolbar onto the canvasInsert excerpt _http _http nopanel true - Enter a name for the HTTP action, then select Create Action
- In the HTTP action
on the right, populate the following details:Insert excerpt _property_settings _property_settings nopanel true
Field | Description | Example Value |
---|---|---|
Name | Name given to the HTTP Node. This will be displayed on the actionflow canvas. | BankHolidays |
HTTP Method | The HTTP method. A drop-down field containing |
: GET, POST, GET or POST, HEAD, PUT, DELETE, other |
. If other is specified a text box will allow the entering of |
a custom value which is not empty and contains only uppercase letters |
. |
Headers: A table of name, value pairs. The name will be treated as a case insensitive string, the value will be treated as a template expression. Duplicate names are permitted and should result in each value being sent in the request.
Get | ||
URL Template | A template that computes the URL of the request. Expects literal values or expressions encapsulated within ${} syntax, for example | https://www.gov.uk/bank-holidays.json |
Body Template | The body is optional for an HTTP message but if it is provided then it is used to carry the HTTP request data. If a body is provided then usually Content-Type and Content-Length headers lines specify the nature of the body associated. In PhixFlow if this evaluates to whitespace only then it is not included in the request. The body expects literal values, or expressions encapsulated within ${} syntax, for example An optional template expression. If this evaluates to only whitespace then it is not include in the request | |
Error |
Expression | An optional JEP expression to determine if the response is an error and so sent on the error output. The expression will have access to the input record (in) and the mapped output response (_result). ----- An optional JEP expression to determine if the response is an error and so sent on the error output |
. | ||
Log Traffic | Toggle on or toggle off. Logs the response of the HTTP request. | |
Maximum HTTP Log Length | Restricts the size of the log traffic. | |
Use Raw URL | If enabled the URL Template value is sent in exactly the format it is provided to the HTTP Node. If not enabled PhixFlow will transpose values to form a valid URL, such as replacing spaces with %20. |
4.
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
5. Hover over the
action on the canvas to see the output connection points Insert excerpt _http _http nopanel true
Output Connection Points
The grid contains a list of output connection points, by default this will be out and error
Output Connection Point | Description |
---|---|
Out | Contains the resulting record of the request. |
Error | Contains the resulting record of the request where it satisfies the error expression specified on the HTTP Node. |
A HTTP action has two outputs. One input request will generate one output record, which will be sent on either the out or error output. A HTTP request will be triggered for each input record and generate one output record.
The response from the server (headers and body) will be treated as the result record, with the input attributes added as passthrough fields.
Output Attributes
The attribute expression will have access to the input (in) and an _result record.
The result record will be structured equivalently to the following JSON document (there is no requirement to actually generate a JSON string to produce the document, just conceptually this is what the string would look like and JEP should operate as if it had come from the equivalent string.
Result fields
body: the response body as a string (string)
url: the url the request was sent to (string)
status: the returned status code as an in (getCode()) (int)
status message: the returns status message (getReasonPhase()) (string)
status family: the returned status code family (100, 200, 300, 400, 500) (int)
error: true if internalError is true, or the error expression (or default expression) returned true (TrueFalse)
transmissionError: true if the error was generated internally by PhixFlow (e.g. a pseudo response for connection timed out etc) (TrueFalse)
headers: a map of header names → array of values ( headerName : [value1, value2]} (Structured Data)
Output Record
An HTTP Node has two output connection points out
and error
. An HTTP Node is triggered for each input record and will generate one output record which will be sent on either the out or error output.
The
output attributes will default to have:status: _result.status
status_message : _result.status_message
contentType: _result.headers.”Content-Type”
resulting record contains the attributes specified by the output connection point, successful records are passed down the out
connection point and records containing an error
are passed down the error connection point. The stricture of the records by default is as follows:
body: The content returned by a successful request. For example, JSON content.
- contentType: The type of response provided by the target HTTP request. For example,
application/json; charset=utf-8
. status: the returned status code.For example,
200
.status message: the returns status message. For example,
OK
.
Headers
A table of name, value pairs. The name will be treated as a case insensitive string, the value will be treated as a template expression. Duplicate names are permitted and should result in each value being sent in the request.
HTML Comment | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
|
Worked Example
Here is a worked example using the Shop Data (available from the Learning Centre).
In this example, we are using:
- A Shop Shipping screen containing a grid of Orders data, a grid of Order Lines data, an area containing a Date form field and buttons - this screen was created using the Multi-Tile template
- A Shop Shipping Popup screen containing a grid of the bank holiday data - this screen was created using the Tile no Buttons template
Tip |
---|
If you are completing this chapter as part of the Actionflow course and using a training instance, the data and screens have already been pre-loaded into the Actionflow Intermediate Application. For these example, we'll be working on the Search button on the Shop Shipping screen, and the Shop Shipping Popup screen. |
GIF/SCREENSHOT OF FINISHED RESULT
Identify Bank Holiday Dates
In this example, we'll create an Actionflow that checks if a new customer's name matches any existing customers, then shows this information in a pop up.
Example
Bank Holidays
Select shipment date date field (date picker), then press Ship Date which changes the status of the order and order lines to completed.
Area underneath showing upcoming bank holidays
Shop Shipping Screen
Shop Shipping Popup Screen
Table Setup
- Create a new
on yourInsert excerpt _tables _tables nopanel true
to save the bank holiday data to, and ensure it contains the following attributes:Insert excerpt _erd _erd nopanel true - Name:
UID
- Type:
String
- Length:
50
- Expression:
_NULL
- Type:
- Name:
Name
- Type:
String
- Length:
200
- Expression:
_NULL
- Type:
- Name:
Date
- Type:
Date
- Leave the Expression field blank
- Type:
- Name:
Country
- Type:
String
- Length:
50
- Leave the Expression field blank
- Type:
- Name:
Initial Configuration
On the Shop Shipping screen, add an Actionflow to the button ("GetDates")
Add an Actionflow to the button that is triggered by the button click
Expand title How? You may notice that right-clicking the button does not display the option to add an Actionflow. The Actionflow must be created using an event handler. See 2.01 Connecting Actionflows to Events.
- Open the
for the button and click on theInsert excerpt _property_settings _property_settings nopanel true Insert excerpt _property_tabs _property_tabs name action nopanel true - In the Action Settings section, choose an Action Method of Actionflow
- Create a new Actionflow
- Open the
HTTP Action Setup
- Select Click to Connect and choose On Click
- Drag a
action onto the canvas and give it a suitable name - this will be used to retrieve the bank holidays from the government JSON URLInsert excerpt _http _http nopanel true - Drag the
connection point node onto theInsert excerpt _input _input nopanel true
actionInsert excerpt _http _http nopanel true - Click on the
action to open its PropertiesInsert excerpt _http _http nopanel true - HTTP Method: GET
- URL: https://www.gov.uk/bank-holidays.json
- Log Traffic:
Insert excerpt _toggle_on _toggle_on nopanel true - Maximum HTTP Log Length: 100000
- Drag a
action onto the canvas and give it a suitable name - this will be used to convert the JSON data into data suitable for our bank holiday tableInsert excerpt _action_json _action_json nopanel true - Connect the out connector from the HTTP node to the JSON node
- Click on the connector between the
action and theInsert excerpt _http _http nopanel true
actionInsert excerpt _action_json _action_json nopanel true - Map across all attributes
JSON Action Setup
- Click on the
action to open its PropertiesInsert excerpt _action_json _action_json nopanel true - Input Expression:
in.body
- Path:
$..events
Output Attributes:
Code Block theme Emacs title Name: Country, Type: String _result.^.^.division
Code Block theme Emacs title Name: Date, Type: Date toDate(_result.date, "yyyy-MM-dd")
Code Block theme Emacs title Name: ID, Type: String toString(_result.date, "yyyyMMdd") + substring(_result.^.^.division, 1,1)
Code Block theme Emacs title Name: Title, Type: String _result.title
- Input Expression:
- Hover over the JSON action and select out
- Create a
actionInsert excerpt _action_save _action_save nopanel true - Primary Table: Shop Bank Holidays
Save Action and Open Screen Action Setup
- Click on the connector between the JSON action and the Save action
Map across the JSON attributes to their relevant attributes on the Save action
Expand title How? - Hover over the Save action and choose out
- Create an
action to open the Shop Shipping Popup screenInsert excerpt _action_screen _action_screen nopanel true
Testing
- Close all open screens and reopen the Shop Shipping screen
- Click the button to run the Actionflow
- If the Actionflow is working, the Shop Shipping Popup screen should open containing all of the bank holiday data from the government website
Background Filter
Tidy up your popup screen by adding a background filter to show the most recent bank holidays.
On the Shop Shipping Popup screen, configure a Background Filter on the
Configuration to only show future datesInsert excerpt _action_view _action_view nopanel true Expand title How? - Right-click on the grid and choose, Show the View Configuration
- In the Data Retrieval Options section of the Properties, select the
icon to create a new background filterInsert excerpt _addIcon _addIcon nopanel true