IacStdActions

HTTP Actions

Standard library HTTP actions for making web requests

send_http_request

std::send_http_request makes an HTTP request to the given URL and exports the response.

Inputs

NameRequiredTypeDescription
urlrequiredstringThe URL for the request. Supported schemes are http and https
bodyoptionalstringThe request body as a string or json object
methodoptionalstringThe HTTP Method for the request. Allowed methods: GET, HEAD, POST
timeout_msoptionalintegerThe request timeout in milliseconds
headersoptionalobjectA map of request header field names and values
pre_conditionoptionalmapPre-conditions that are evaluated before a command is executed
post_conditionoptionalmapPost-conditions that are evaluated after a command is executed

Pre-conditions

Pre-conditions are assertions that are evaluated before a command is executed. They can be used to determine if the command should be executed or if a specific behavior should be executed based on the result of the assertion.

PropertyDescription
behaviorThe behavior if the pre-condition assertion does not pass. Options: halt (default), log, skip
assertionThe assertion to check. Should evaluate to a boolean or use std::assert_eq and similar functions

Post-conditions

Post-conditions are assertions that are evaluated after a command is executed. They can be used to determine if the command should be re-executed.

PropertyDescription
retriesNumber of times to re-execute the command if assertion fails. Default: 0
backoff_msMilliseconds to wait before re-executing. Default: 1000
behaviorThe behavior if the post-condition assertion does not pass. Options: halt (default), log, skip, continue
assertionThe assertion to check

Outputs

When the send_http_request action is successfully executed, the following outputs are attached to the action:

NameTypeDescription
response_bodystringThe response body returned as a string
status_codeintegerThe HTTP response status code

Example

action "example" "std::send_http_request" {
  url = "https://example.com"
}

output "status" {
  value = action.example.status_code
}
// > status: 200

POST Request Example

action "create_resource" "std::send_http_request" {
    description = "Create a new resource"
    url = "https://api.example.com/resources"
    method = "POST"
    headers = {
        "Content-Type" = "application/json"
    }
    body = {
        "name" = variable.name,
        "value" = variable.value
    }
}

Request with Authentication

action "api_call" "std::send_http_request" {
    description = "Fetch data from API"
    url = "https://api.example.com/data"
    method = "GET"
    headers = {
        "Authorization" = "Bearer ${variable.token}"
    }
}

output "response" {
    value = action.api_call.response_body
}

output "status" {
    value = action.api_call.status_code
}

On this page