SolanaドキュメントInfrastructure as Code標準ライブラリ

HTTPアクション

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(デフォルト)、logskip
assertionチェックするアサーション。ブール値に評価されるか、std::assert_eq および類似の関数を使用する必要があります

事後条件

事後条件は、コマンドの実行後に評価されるアサーションです。コマンドを再実行するかどうかの判断に使用できます。

プロパティ説明
retriesアサーションが失敗した場合にコマンドを再実行する回数。デフォルト: 0
backoff_ms再実行前に待機するミリ秒数。デフォルト: 1000
behavior事後条件のアサーションが失敗した場合の動作。オプション: halt(デフォルト)、logskipcontinue
assertionチェックするアサーション

出力

send_http_request アクションが正常に実行されると、以下の出力がアクションに添付されます:

名前説明
response_bodystring文字列として返されたレスポンスボディ
status_codeintegerHTTPレスポンスのステータスコード

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?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。