C.W.K.
Stream
Lesson 05 of 08 · published

curl — Shell 의 HTTP 클라이언트

~13 min · curl, http, api

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

모든 곳의 HTTP/{,S}, FTP, ... 클라이언트

curl 이 HTTP 요청 하나 보내고 응답 출력. 모든 API 문서가 예시로 보여주는 도구. curl https://example.com 이 HTML 출력.

일상 flag

  • -L — redirect 따라가기.
  • -sS — silent + error 만 표시. pipe 친화 default.
  • -o file — 파일로 저장. -O 는 URL 의 파일명 사용.
  • -X POST / -X PUT — 메서드 변경.
  • -H 'Header: Value' — 헤더. 반복 가능.
  • -d 'data' — POST 바디 (form-encoded).
  • --data-urlencode 'key=value with spaces' — URL 인코딩.
  • --data @body.json — 파일에서 읽기.
  • -u user:pass — basic auth.
  • -i / -I — 헤더 포함 / 헤더만.
  • -w '%{http_code}\n' — 커스텀 출력 (status, time 등).

JSON POST

curl -sS https://api.example.com/items \
  -H 'Authorization: Bearer ${TOKEN}' \
  -H 'Content-Type: application/json' \
  -d '{"name":"pippa","qty":3}'

GET + auth + jq

curl -sS -H 'Authorization: token ghp_xxx' \
  https://api.github.com/user/repos | jq '.[].name'

큰 파일 진행도 보면서 다운로드

curl -L -o ubuntu.iso --progress-bar https://...

헬스 체크 one-liner

curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://api

아무 튜토리얼의 curl 붙이지 마

curl ... | bash 같은 pipe-to-shell 인스톨러는 서버가 보내는 거 다 실행. 서버 손상 시 그쪽 코드 그대로 실행. 파일로 저장 → 읽기 → 실행.

Code

실제 API 호출 패턴·bash
# GitHub user repos (no auth, public)
curl -sS https://api.github.com/users/cli/repos | jq '.[].full_name' | head
# Health check
curl -sS -o /dev/null -w 'http=%{http_code} dns=%{time_namelookup}s total=%{time_total}s\n' \
  https://api.openai.com
# POST JSON from file
curl -sS -X POST https://example/api \
  -H 'Content-Type: application/json' \
  --data @body.json

External links

Exercise

curl -sS https://api.github.com/repos/cli/cli | jq '.stargazers_count, .forks_count'. curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://example.com. 작은 파일 다운로드 curl -O https://....

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.