send_http_request
std::send_http_request
は、指定されたURLにHTTPリクエストを送信し、レスポンスをエクスポートします。
入力
| 名前 | 必須 | 型 | 説明 |
|---|---|---|---|
url | 必須 | string | リクエストのURL。サポートされているスキームはhttpとhttps |
body | 任意 | string | 文字列またはJSONオブジェクトとしてのリクエストボディ |
method | 任意 | string | リクエストのHTTPメソッド。使用可能なメソッド: GET、HEAD、POST |
timeout_ms | 任意 | integer | リクエストのタイムアウト(ミリ秒) |
headers | 任意 | object | リクエストヘッダーフィールド名と値のマップ |
pre_condition | 任意 | map | コマンド実行前に評価される事前条件 |
post_condition | 任意 | map | コマンド実行後に評価される事後条件 |
事前条件
事前条件とは、コマンド実行前に評価されるアサーションです。コマンドを実行すべきかどうか、またはアサーションの結果に基づいて特定の動作を実行すべきかどうかを判断するために使用できます。
| プロパティ | 説明 |
|---|---|
behavior | 事前条件のアサーションが通過しない場合の動作。オプション: halt(デフォルト)、log、skip |
assertion | チェックするアサーション。ブール値に評価されるか、std::assert_eq および類似の関数を使用する必要があります |
事後条件
事後条件は、コマンドの実行後に評価されるアサーションです。コマンドを再実行するかどうかの判断に使用できます。
| プロパティ | 説明 |
|---|---|
retries | アサーションが失敗した場合にコマンドを再実行する回数。デフォルト: 0 |
backoff_ms | 再実行前に待機するミリ秒数。デフォルト: 1000 |
behavior | 事後条件のアサーションが失敗した場合の動作。オプション: halt(デフォルト)、log、skip、continue |
assertion | チェックするアサーション |
出力
send_http_request
アクションが正常に実行されると、以下の出力がアクションに添付されます:
| 名前 | 型 | 説明 |
|---|---|---|
response_body | string | 文字列として返されたレスポンスボディ |
status_code | integer | HTTPレスポンスのステータスコード |
例
action "example" "std::send_http_request" {url = "https://example.com"}output "status" {value = action.example.status_code}// > status: 200
POSTリクエストの例
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}}
認証付きリクエスト
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}
Is this page helpful?