Integrate with HTTP services
CloudFlow lets you invoke any HTTP service using HTTP integration. Each time an HTTP integration is triggered, an HTTP request is sent to the target URL. This topic describes the sample code, parameters, return value, and supported integration modes for integrating CloudFlow with HTTP services.
Sample code
The following code is a typical snippet for integrating CloudFlow with an HTTP service.
Type: StateMachine
Name: MyWorkflow
SpecVersion: v1
StartAt: Request
States:
- Type: Task
Name: Request
Action: HTTP:Request
TaskMode: RequestComplete
Description: an example of an HTTP invocation
Parameters:
url: https://www.example.com
method: Get
End: true
The following section describes the code.
-
Action: The value must be
HTTP:Request. -
TaskMode: The supported execution modes are Request-response (RequestComplete) and Wait for a custom callback (WaitForCustomCallback).
-
Name and Description: Configure a name and description as needed.
Parameter description
|
Parameter name |
Required |
Description |
Example |
|
url |
Yes |
The URL of the request. Enter a complete URL, including the protocol. The URL provider must ensure that the address is accessible from the public network. Otherwise, the workflow cannot correctly execute the integration. |
https://www.example.com |
|
method |
Yes |
The HTTP method used to initiate the request. Valid values:
|
GET |
|
body |
No |
The content of the request.
|
|
|
headers |
No |
The request headers used in the HTTP request. |
|
Return value
The result of the business request is wrapped in a JSON object, as shown in the following example.
{
"Header":{
"Content-Type": "application/json;charset=UTF-8",
"Access-Control-Allow-Methods": "GET,POST,OPTIONS"
},
"Code": 200,
"Body": "hello world"
}
Execution modes
When CloudFlow integrates with an HTTP service, only two integration modes are supported: Request-response (RequestComplete) and Wait for a custom callback (WaitForCustomCallback).
RequestComplete
After an HTTP call is initiated, the corresponding task is complete when the current HTTP request is finished. The data returned from the HTTP server is the output of the current task.
WaitForCustomCallback
After an HTTP call is initiated, the flow execution is automatically paused. The flow resumes after the backend system initiates a callback. The callback process depends on a token that distinguishes different flows, executions, and steps. This token is passed to the invoked system in the header during the HTTP call. The key for this token is X-FnF-Http-Callback-Task-Token.
You can also customize the token's key by referencing the $Context.Current.TaskToken expression in the parameters.