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
| Name | Required | Type | Description |
|---|---|---|---|
url | required | string | The URL for the request. Supported schemes are http and https |
body | optional | string | The request body as a string or json object |
method | optional | string | The HTTP Method for the request. Allowed methods: GET, HEAD, POST |
timeout_ms | optional | integer | The request timeout in milliseconds |
headers | optional | object | A map of request header field names and values |
pre_condition | optional | map | Pre-conditions that are evaluated before a command is executed |
post_condition | optional | map | Post-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.
| Property | Description |
|---|---|
behavior | The behavior if the pre-condition assertion does not pass. Options: halt (default), log, skip |
assertion | The 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.
| Property | Description |
|---|---|
retries | Number of times to re-execute the command if assertion fails. Default: 0 |
backoff_ms | Milliseconds to wait before re-executing. Default: 1000 |
behavior | The behavior if the post-condition assertion does not pass. Options: halt (default), log, skip, continue |
assertion | The assertion to check |
Outputs
When the send_http_request action is successfully executed, the following outputs are attached to the action:
| Name | Type | Description |
|---|---|---|
response_body | string | The response body returned as a string |
status_code | integer | The HTTP response status code |
Example
action "example" "std::send_http_request" {
url = "https://example.com"
}
output "status" {
value = action.example.status_code
}
// > status: 200POST 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
}