What is a HTTP Action?
HTTP actions performs HTTP(S) requests to external APIs and returns the response.
Creating HTTP Actions
- Click and drag the HTTP icon from the toolbar onto the canvas
- Enter a name for the HTTP action, then select Create Action
- In the HTTP action Properties on the right, populate the following details:
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. | 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 | Optional. If this 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 | |
Error Expression | Optional. A 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). | |
Log Traffic | Toggle on to logs the response of the HTTP request. | |
Maximum HTTP Log Length | Available if Log Traffic is toggled on . Restricts the size of the log traffic. | |
Use Raw URL | Toggle on to send the URL Template value in exactly the format it is provided to the HTTP Node. If toggled off PhixFlow will transpose values to form a valid URL, such as replacing spaces with %20. |
4. Apply and Close all settings
5. Hover over the HTTP action on the canvas to see the output connection points
Output Connection Points
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..
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. |
The output records contain 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 structure of the records by default are 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
Headers are typically used to specify information for the request, such as character sets, session tokens or passwords. Headers can make use of the Secret Key Details.
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
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 retrieves bank holiday dates in the UK from the government website in JSON format and map this onto a screen in a grid.
Table Setup
- Create a new Table on your ERD to save the bank holiday data to, and ensure it contains the following attributes:
- 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
HTTP Action Setup
- Select Click to Connect and choose On Click
- Drag a HTTP action onto the canvas and give it a suitable name - this will be used to retrieve the bank holidays from the government JSON URL
- Drag the input connection point node onto the HTTP action
- Click on the HTTP action to open its Properties
- HTTP Method: GET
- URL: https://www.gov.uk/bank-holidays.json
- Log Traffic:
- Maximum HTTP Log Length: 100000
- Drag a JSON 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 table
- Connect the out connector from the HTTP node to the JSON node
- Click on the connector between the HTTP action and the JSON action
- Map across all attributes
JSON Action Setup
- Click on the JSON action to open its Properties
- Input Expression:
in.body
- Path:
$..events
Output Attributes:
Name: Country, Type: String_result.^.^.division
Name: Date, Type: DatetoDate(_result.date, "yyyy-MM-dd")
Name: ID, Type: StringtoString(_result.date, "yyyyMMdd") + substring(_result.^.^.division, 1,1)
Name: Title, Type: String_result.title
- Input Expression:
- Hover over the JSON action and select out
- Create a Save action
- Primary Table:
Shop Bank Holidays
- Primary Table:
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
- Hover over the Save action and choose out
- Create an Open Screen action to open the Shop Shipping Popup screen
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 View Configuration to only show future dates