Using the HTTP Command

Updated 1 week ago by Michael Cretzman

You can use the HTTP command to run HTTP methods containing URLs, methods, headers, assertions, and variables. You use the HTTP template in a Harness Workflow.

Create HTTP Command

  1. In your Workflow, click Add Command. The Add Command dialog appears.
  2. To create a new HTTP command, click HTTP. To use an existing HTTP command, select a Template Library and link the HTTP command template to your Workflow. For this example, we will create a new HTTP command.
    The HTTP settings appear.

The following table describes the HTTP command options.

Field

Description

URL

Enter the URL for the HTTP call.

Method

Select the HTTP method.

Header

Enter the media type for the message. For example, if you are using the GET method, the header is used to specify the GET response body message type Harness will check, such as content-type: application/json.

For multiple header entries, separate the headers with commas:

Content-Type: application/json, Cache-Control: no-cache

Body

Enter the message body (if any) of the HTTP message.

Assertion

The assertion is used to validate the incoming response. For example, if you wanted to check the health of an HTTP connection, you could use the assertion ${httpResponseCode}==200.

To see the available expressions, simply enter ${ in the Assertions field. The HTTP expressions are described in the HTTP section of Variables and Expressions in Harness.

Timeout

Enter a value, in seconds, for how long Harness should wait for a response from the server you specified in URL.

Process Additional Variables

Create variables using built-in Harness expressions. In Name, enter a name for the variable. In Expression, enter an expression that obtains some value from the HTTP response. Harness supports these functors and methods:

  • JSON Path:
    • select(). Example: ${json.select("path-in-response", httpResponseBody)}
    • object(). Example: ${json.object(httpResponseBody).item}
    • list(). Example: {json.list(\"store.book\", httpResponseBody).get(2).isbn}
  • XPath:
    • select(). Example: ${xml.select("/bookstore/book[1]/title", httpResponseBody)}

For details, see JSON and XML Functors.

Publish output in the context

Select this option to create a variable containing the content of the HTTP response, or the content of a variable specified in Process Additional Variables.

in Publish Variable Name, enter a unique name for the output variable. You will use this name to reference the variable elsewhere. For example, if the Publish Variable Name is region, you would reference it with ${context.region}.

If reference a variable named FIELD in Process Additional Variables, you would use ${region.FIELD}.

In Scope, select PipelineWorkflow, or Phase. The output variable are available within the scope you set here. The scope you select is useful for preventing variable name conflicts. You might use a Workflow with published variables in multiple pipelines, so scoping the variable to Workflow will prevent conflicts with other Workflows in the Pipeline.

Next Steps


How did we do?