Skip to main content

HTTP Task

"type" : "HTTP"

Introduction

An HTTP task is useful when you have a requirements such as

  1. Making calls to another service that exposes an API via HTTP
  2. Fetch any resource or data present on an endpoint

Use Cases

If we have a scenario where we need to make an HTTP call into another service, we can make use of 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 Conductor manage it directly. This can reduce the code you have to maintain and allows for a lot of flexibility.

Configuration

HTTP task is defined directly inside the workflow with the task type HTTP.

nametypedescription
http_requestHttpRequestJSON object (see below)

Inputs

NameTypeExampleDescription
uriStringURI for the service. Can be a partial when using vipAddress or includes the server address.
methodStringHTTP method. One of the GET, PUT, POST, DELETE, OPTIONS, HEAD
acceptStringAccept header as required by server. Defaults to application/json
contentTypeStringContent Type - supported types are text/plain, text/html, and application/json (Default)
headersMap[String, Any]A map of additional http headers to be sent along with the request.
bodyMap[]Request body
vipAddressStringWhen using discovery based service URLs.
asyncCompleteBooleanTODO: Link to detailsfalse 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.
oauthConsumerKeyStringOAuth client consumer key
oauthConsumerSecretStringOAuth client consumer secret
connectionTimeOutIntegerConnection Time Out in milliseconds. If set to 0, equivalent to infinity. Default: 100.
readTimeOutIntegerRead Time Out in milliseconds. If set to 0, equivalent to infinity. Default: 150.

Output

nametypedescription
responseMapJSON body containing the response if one is present
headersMap[String, Any]Response Headers
statusCodeIntegerHttp Status Code
reasonPhraseStringHttp Status Code's reason phrase

Examples

Following is the example of HTTP task with 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 the example of HTTP task with 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 the example of HTTP task with 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 the example of HTTP task with 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

Best Practices

  1. Why are my HTTP tasks not getting picked up?
    1. 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
  2. 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?
    1. 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 under http_request add the two following parameters (the timeouts are in milliseconds):
          "connectionTimeOut": 1000,
"readTimeOut": 1000
  1. Can I retry my HTTP Tasks?

    1. Yes. See Extending System Tasks to see how to add retries, and retry parameters to your HTTP Task.
  2. I'm getting rate limited. Can I slow down my HTTP Task?

    1. Yes! By Extending System Tasks, and adding the following parameters:
      "rateLimitPerFrequency": 100,
    "rateLimitFrequencyInSeconds": 60,
    1. This will allow only 100 calls to the API endpoint in 60 seconds. Modify the values as required.