HTTP Task
"type" : "HTTP"
Introduction
An HTTP task is useful when you have requirements such as
- Making calls to another service that exposes an API via HTTP
- Fetch any resource or data present on an endpoint
Use Cases
If we have a scenario where we need to make an HTTP call to another service, we can use HTTP tasks. You can use the data returned from the HTTP call in your subsequent tasks as inputs. Using HTTP tasks, you can avoid having to write the code that talks to these services and instead let the Conductor manage it directly. This can reduce the code you must maintain and allow for much flexibility.
Configuration
HTTP task is defined directly inside the workflow with the task type HTTP
.
name | type | description |
---|---|---|
http_request | HttpRequest | JSON object (see below) |
Inputs
Name | Type | Example | Description |
---|---|---|---|
uri | String | URI for the service. It can be a partial value when using vipAddress or includes the server address. | |
method | String | HTTP method. One of the GET, PUT, POST, DELETE, OPTIONS, HEAD | |
accept | String | Accept header as required by the server. Defaults to application/json | |
contentType | String | Content Type - supported types are text/plain , text/html , and application/json (Default) | |
headers | Map[String, Any] | A map of additional http headers to be sent along with the request. | |
body | Map[] | Request body | |
vipAddress | String | When using discovery-based service URLs. | |
asyncComplete | Boolean | TODO: Link to details | false to mark status COMPLETED upon execution; true to keep it IN_PROGRESS, wait for an external event (via Conductor or SQS or EventHandler) to complete it. |
oauthConsumerKey | String | OAuth client consumer key | |
oauthConsumerSecret | String | OAuth client consumer secret | |
connectionTimeOut | Integer | Connection Time Out in milliseconds. If set to 0, equivalent to infinity. Default: 100. | |
readTimeOut | Integer | Read Time Out in milliseconds. If set to 0, equivalent to infinity. Default: 150. |
Output
name | type | description |
---|---|---|
response | Map | JSON body containing the response if one is present |
headers | Map[String, Any] | Response Headers |
statusCode | Integer | HTTP Status Code |
reasonPhrase | String | HTTP Status Code's reason phrase |
Examples
Following is an example of an HTTP task with the GET
method.
We can use variables in our URI, as show in the example below. For details on how to use inputs, refer to the Task Inputs page.
{
"name": "Get Example",
"taskReferenceName": "get_example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/${workflow.input.queryid}",
"method": "GET"
}
},
"type": "HTTP"
}
Following is an example of an HTTP task with the POST
method.
Here we are using variables for our POST body which happens to be data from a previous task. This is an example of how you can chain HTTP calls to make complex flows happen without writing any additional code.
{
"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"
}
Following is an example of an HTTP task with the PUT
method.
{
"name": "http_put_example",
"taskReferenceName": "put_example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/1",
"method": "PUT",
"body": {
"title": "${get_example.output.response.body.title}",
"userId": "${get_example.output.response.body.userId}",
"action": "doSomethingDifferent"
}
}
},
"type": "HTTP"
}
Following is an example of an HTTP task with the DELETE
method.
{
"name": "DELETE Example",
"taskReferenceName": "delete_example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/1",
"method": "DELETE"
}
},
"type": "HTTP"
}
Codelabs with HTTP tasks
- Running the first workflow uses HTTP Task to call an API.
- Hello World Part 2 uses the HTTP task to send an IP Address and receive a location.
- Order Fulfillment Part 4 calls an API to reorder widgets.
- Sequential HTTP Tasks makes two HTTP tasks. Data from the first response is used as input in the 2nd task.
Best Practices
- Why are my HTTP tasks not getting picked up?
- We might have too many HTTP tasks in the queue. There is a concept called Isolation Groups that you can rely on for prioritizing certain HTTP tasks over others. Read more here: Isolation Groups.
- Why is my HTTP Task timing out with
Failed to invoke HTTP task due to: java.lang.Exception: I/O error on GET request for "<url>": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
?- The default timeout for an HTTP request is 150ms. If your API takes longer than this, you will need to increase the timeout parameters. In your
inputParameters
underhttp_request
, add the two following parameters (the timeouts are in milliseconds):
- The default timeout for an HTTP request is 150ms. If your API takes longer than this, you will need to increase the timeout parameters. In your
"connectionTimeOut": 1000,
"readTimeOut": 1000
Can I retry my HTTP Tasks?
- Yes. You can add retries and retry parameters to your HTTP Task.
I'm getting rate limited. Can I slow down my HTTP Task?
- Yes! By extending system tasks and adding the following parameters:
"rateLimitPerFrequency": 100,
"rateLimitFrequencyInSeconds": 60,- This will allow only 100 calls to the API endpoint in 60 seconds. Modify the values as required.