솔라나 문서코드형 인프라표준 라이브러리

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 (기본값), log, skip
assertion확인할 어서션입니다. 불리언으로 평가되거나 std::assert_eq 및 유사한 함수를 사용해야 합니다

사후 조건

사후 조건은 명령이 실행된 후 평가되는 어설션입니다. 명령을 재실행해야 하는지 여부를 결정하는 데 사용할 수 있습니다.

속성설명
retries어설션이 실패할 경우 명령을 재실행할 횟수. 기본값: 0
backoff_ms재실행 전 대기 시간(밀리초). 기본값: 1000
behavior사후 조건 어설션이 통과되지 않을 경우의 동작. 옵션: halt (기본값), log, skip, continue
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?

목차

페이지 편집