π‘ cURL CLI Sheet: HTTP Headers & REST API β Executive Summary
Technical architectural analysis, practical configuration manifests, and deployment instructions for cURL CLI Sheet: HTTP Headers & REST API.
Exec
bash
#curl test
curl -sSL -o /dev/null -D - ${URL}
#download λ°κΈ°(wget)
curl -LO ${URL}
curl -L ${URL} -o ${FILENAME}
#response Header ν¬ν¨ μΆλ ₯
curl -i
#user μΈμ¦μ 보 ν¬ν¨
curl -u id:pw https://{ URL }
#X509 μΈμ¦ 무μ
curl -k https:{ URL }
#verbose
curl -v { url }
#cacert cert key
curl --cacert *.pem --key *.pem --cert *.pem {{ url }}
#jq(json to pretty)
curl {url} | jq ''
#request Header
curl -H"Name: Value"
curl --header "Name: Value"
#request body
curl -d"{}"
curl --data "{}"
header
bash
-H "Authorization: bearer ${token}"
-H "Authorization: basic $(echo "${username}:${password}" | base64)"
-H "Content-Type: application/json" #νμ΄λ‘λμ λ°μ΄ν° νμ
-H "Accept: application/json" #λ΄κ° 리μ€ν°μ€ λ°μ μ μλ νμ
-H "Host: ${domain}" #ipλ‘μ μμ²μ domainμ μμΈ μ μμ.
flags
bash
-L, --location
(HTTP) μλ²κ° μμ²ν νμ΄μ§κ° λ€λ₯Έ μμΉλ‘ μ΄λνλ€κ³ λ³΄κ³ νλ κ²½μ°(Lo-
μμ΄μ¨: ν€λ λ° 3XX μλ΅ μ½λ), μ΄ μ΅μ
μ μ¬μ©νλ©΄ μ»¬μ΄ μ μμΉμμ μμ²μ λ€μ μ€ννκ² λ©λλ€. λ§μ½μ
-i, --include λλ -I, --headμ ν¨κ» μ¬μ©νλ©΄ μμ²λ λͺ¨λ νμ΄μ§μ ν€λκ° νμλ©λλ€. μΈμ¦ν λβ
μ»¬μ΄ μ¬μ©λλ©΄ 컬μ μ격 μ¦λͺ
μ μ΄κΈ° νΈμ€νΈμλ§ λ³΄λ
λλ€. 리λλ μ
μΌλ‘ μΈν΄ μ»¬μ΄ λ€λ₯Έ κ²½μ°
νΈμ€νΈμμλ μ¬μ©μ+λΉλ°λ²νΈλ₯Ό κ°λ‘μ± μ μμ΅λλ€. λ³κ²½ λ°©λ²μ λν΄μλ --location-trustedλ μ°Έμ‘°νμΈμ.
μ΄κ². --max-redirs μ΅μ
μ μ¬μ©νμ¬ λ°λΌμΌ ν 리λλ μ
μμ μ νν μ μμ΅λλ€.
μ»¬μ΄ λ¦¬λλ μ
μ λ°λ₯΄κ³ μμ²μ΄ POSTμΈ κ²½μ° λ€μκ³Ό κ°μ μμ²μ GETκ³Ό ν¨κ» 보λ
λλ€.
HTTP μλ΅μ 301, 302 λλ 303μ
λλ€. μλ΅ μ½λκ° λ€λ₯Έ 3xx μ½λμΈ κ²½μ° μ»¬μ
μμ λμ§ μμ λμΌν λ°©λ²μ μ¬μ©νμ¬ λ€μ μμ²μ μνν©λλ€.
μ μ© μ΅μ
μ μ¬μ©νμ¬ 30x μλ΅ νμ POST μμ²μ GETμΌλ‘ λ³κ²½νμ§ μλλ‘ μ»¬μ μ§μν μ μμ΅λλ€.
μ¦, --post301, --post302 λ° --post303μ
λλ€.
-X, --requestλ‘ μ€μ λ λ©μλλ μ»¬μ΄ μ¬μ©νκΈ° μν΄ μ ννλ λ©μλλ₯Ό λ체ν©λλ€.
μ:
컬 -L https://example.com
--resolve λ° --alt-svcλ μ°Έμ‘°νμΈμ.
Features
Remove stdout
bash
# λ λ€ λμΌν¨
curl $ep -o /dev/null
curl $ep 1>/dev/null
Private domain, private rootca certificate /etc/hosts without registration https wget
bash
curl -LO https://${domain}/${path}/${upstream_file} \
--cacert ${cacert} \
--resolve ${domain}:443:${ip}
Send json file via POST
bash
vi ./test.json
curl -X POST https://wh.jandi.com/connect-api/webhook/20317820/626c58e4bc0497e2aa35492d01518385 \
-H "Accept: application/vnd.tosslab.jandi-v2+json" \ #리νμ€νΈλ°λ λ°±μλκ° μ΄ν΄κ°λ₯ν νμ
λͺ
μ
-H "Content-Type: application/json" \ #리μ€ν°μ€ λ°μ μμ²νμ
μ§μ
--data @test.json # file
Send to function (in the shell)
bash
#!/bin/bash
#ceph-df-print file export path
CEPH_DF_PRINT=/Enterprise Cloud_package/jandi/ceph-df-print
#function: read ceph-df-print file and display
generate_post_data() {
cat << EOF
{
"body": "[Ceph] μν μ‘°ν ($(date "+%Y-%m-%d %I:%M:%S %p"))",
"connectColor": "#FAC11B",
"connectInfo": [
{
"title": "Ceph HOST Status",
"description": "$(cat $CEPH_DF_PRINT | grep -e host -e root | awk 'NR==1 { print "NAME", "TOTAL", "AVAIL", "USAGE"} {gsub(/"/,""); print "["$19"-"$20"]",$4$5, $14$15,$8$9 "(" $16 "%)" }' | column -t -s' ' | awk '{printf "%s\\n", $0}')"
},
{
"title": "Ceph OSD Status",
"description": "$(cat $CEPH_DF_PRINT | grep osd | sort -r -k 17 | awk 'NR==1 { print "NAME", "TOTAL", "AVAIL", "USAGE"} {gsub(/"/,""); print "["$21"]", $5$6, $15$16, $9$10 "(" $17 "%)" }' | column -t -s' ' | awk '{printf "%s\\n", $0}')"
}
]
}
EOF
}
curl -X POST https://wh.jandi.com/connect-api/webhook/20317820/7e31d57c8d58bc28151e73926a371ad9 \
-H "Accept: application/vnd.tosslab.jandi-v2+json" \
-H "Content-Type: application/json" \
--data "$(generate_post_data)"




Leave a Reply