HTTP
The HTTP task is used to make calls to remote services exposed over HTTP/HTTPS. It supports various HTTP methods, headers, body content, and other configurations needed for interacting with APIs or remote services.
The HTTP task evaluates the parameters provided, constructs the HTTP request accordingly, and sends it to the specified URI. It handles the response by extracting useful information like status code, headers, and body content, which can be used in subsequent tasks in the workflow.
Task parameters
Configure these parameters for the HTTP task.
Parameter | Description | Required/ Optional |
---|---|---|
inputParameters.uri | The URI for the service. It can be a partial value when using vipAddress or it can be the server address. | Required. |
inputParameters.method | The HTTP method. Supported methods:
| Required. |
inputParameters.accept | The accept header required by the server. The default value is application/json . Supported types:
| Optional. |
inputParameters.contentType | The content type for the server. The default value is application/json . Supported types:
| Optional. |
inputParameters.hedgingConfig.maxAttempts | The maximum number of parallel requests to send. The system will use the response from the first successful attempt, helping reduce tail latencies in remote services. Note: Hedging makes parallel requests, so use it only for idempotent services. | Optional. |
inputParameters.headers | A map of additional HTTP headers to be sent along with the request. Supported types:
| Optional. |
inputParameters.body | The request body for POST, PUT, or PATCH methods. Can be text or parameters such as string, number, boolean, null, or object/array. | Required for POST, PUT, or PATCH. |
inputParameters.encode | Determines whether the URI needs encoding. When set to true , the Conductor will automatically encode the query parameters before sending the HTTP request. Set this to false if the URI is already encoded. The default value is true. | Optional. |
Caching parameters
You can cache the task outputs using the following parameters. Refer to Caching Task Outputs for a full guide.
Parameter | Description | Required/ Optional |
---|---|---|
cacheConfig.ttlInSecond | The time to live in seconds, which is the duration for the output to be cached. | Required if using cacheConfig. |
cacheConfig.key | The cache key is a unique identifier for the cached output and must be constructed exclusively from the task’s input parameters. It can be a string concatenation that contains the task’s input keys, such as ${uri}-${method} or re_${uri}_${method} . | Required if using cacheConfig. |
Schema parameters
You can enforce input/output validation for the task using the following parameters. Refer to Schema Validation for a full guide.
Parameter | Description | Required/ Optional |
---|---|---|
taskDefinition.enforceSchema | Whether to enforce schema validation for task inputs/outputs. Set to true to enable validation. | Optional. |
taskDefinition.inputSchema | The name and type of the input schema to be associated with the task. | Required if enforceSchema is set to true. |
taskDefinition.outputSchema | The name and type of the output schema to be associated with the task. | Required if enforceSchema is set to true. |
Other generic parameters
Here are other parameters for configuring the task behavior.
Parameter | Description | Required/ Optional |
---|---|---|
optional | Whether the task is optional. The default is false. If set to true, the workflow continues to the next task even if this task is in progress or fails. | Optional. |
asyncComplete | Whether the task is completed asynchronously. The default value is false.
| Optional. |
Task configuration
This is the task configuration for an HTTP task.
{
"name": "http",
"taskReferenceName": "http_ref",
"type": "HTTP",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true,
"hedgingConfig": {
"maxAttempts": "4"
},
"headers": {
"header-1": "${workflow.input.header-1}"
},
"body": {
"key": "value"
}
},
"asyncComplete": true
}
Task output
The HTTP task will return the following parameters.
Parameter | Description |
---|---|
response | A JSON object representing the response, if present. |
headers | An object containing the metadata about the response. |
statusCode | The HTTP status code indicating success or failure of the request. |
reasonPhrase | The reason phrase associated with the HTTP status code. |
body | The response body containing the data returned by the API. |
Adding an HTTP task in UI
An HTTP task can be configured manually through the UI or automatically populated using registered service definitions.
- Using registered services
- Manually configuring an HTTP task
To add an HTTP task using registered services:
- In your workflow, select the (+) icon and add an HTTP task.
- Select Populate from remote services.
- In Service, select the registered HTTP service.
- In Service method, select the required endpoint.
- Select Populate.
- (Optional) In Hedging Config > Maximum attempts, enter a value for parallel hedged requests to reduce latency.
This method automatically fills in the HTTP task parameters based on the selected service. It is recommended if you have already registered your HTTP services in Orkes Conductor.
To add an HTTP task:
- In your workflow, select the (+) icon and add an HTTP task.
- Choose the HTTP method for sending requests from the Method drop-down.
- In URL, add the URI to be called by the HTTP task.
- In Accept, select the accept header as required by the server.
- In Content-Type, select the content type for the server.
- (Optional) In Hedging Config > Maximum attempts, enter a value for parallel hedged requests to reduce latency.
- (Optional) In Other-headers, add any additional HTTP headers to be sent along with the request.
- In Body, add the request body when using PUT, POST, or PATCH method.
- (Optional) Enable or disable Encode to specify if the URI needs to be encoded.
- (Optional) Set Async complete to true if the task is to be completed asynchronously.
Examples
Here are some examples for using the HTTP task.
Sending a POST request
Sample workflow for sending an HTTP POST request:
// task configuration
{
"name": "http_post_example",
"taskReferenceName": "post_example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/",
"method": "POST",
"body": {
"title": "${get_example.output.response.body.title}",
"userId": "${get_example.output.response.body.userId}",
"action": "doSomething"
}
}
},
"type": "HTTP"
}
Orchestrating Long-Running APIs
Explore the full tutorial on orchestrating long-running APIs.
Sample Workflow using ‘Async Complete’ option
The asyncComplete option in the HTTP task configuration allows tasks to be marked as completed asynchronously, providing flexibility in workflow execution. Here's an example enabling ‘asyncComplete’:
{
"name": "async_complete_example",
"description": "Edit or extend this sample workflow. Set the workflow name to get started",
"version": 1,
"tasks": [
{
"name": "http_task_85tf2",
"taskReferenceName": "http_task_85tf2_ref",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"connectionTimeOut": 3000,
"readTimeOut": "3000",
"accept": "application/json",
"contentType": "application/json"
}
},
"type": "HTTP",
"asyncComplete": true
}
],
"schemaVersion": 2,
"ownerEmail": "john.doe@acme.com"
}
Now, let’s run this in the Developer Edition.
- Under Workflow Name, choose async_complete_example.
- Click Run Workflow.
Upon execution, the HTTP task remains “Scheduled” instead of completing immediately, allowing for asynchronous completion. The task can be completed using various methods:
- Using API
- From Conductor UI
Once the workflow runs, note the generated workflowId displayed near the workflow name on the execution page.
Use this workflowId along with the taskRefName to complete the task via the following API:
POST /api/tasks/{workflowId}/{taskRefName}/{status}
From the workflow execution page, click on the task and manually update the status to “COMPLETED.”
Employing these methods allows you to asynchronously complete your workflow, which is beneficial when pausing the workflow for external interventions.