curl 에서 코드로
모든 curl 명령은 실제 코드로 바로 변환할 수 있어요
⏱ 예상 ~8분
01 · 읽기
비밀은 이거예요: curl 은 단순한 테스트 도구가 아니에요. 변환 가이드 예요.
작성하는 모든 curl 명령은 JavaScript 의 fetch 호출, Python 의 requests 호출, 혹은 다른 어떤 HTTP client 와도 1:1 로 대응돼요. 일단 curl 에서 요청이 동작하면 코드로 변환하는 건 기계적이에요 — Claude Code가 몇 초 안에 끝내요.
이게 모든 엔지니어의 워크플로예요:
1. API 이해하기 (문서 읽기) 2. curl 로 요청 테스트 (동작 확인) 3. 코드로 변환 (프로젝트에 복사) 4. 응답 처리 (데이터 파싱 및 사용)
핵심 정리
- curl 플래그는 코드에 직접 대응돼요: -H → headers 객체, -d → body
- 동작하는 curl 명령은 Claude Code 에 붙여넣어요: '이걸 JavaScript fetch 로 변환해 줘'
- 변환은 기계적이에요 — 어려운 건 curl 을 동작시키는 거지 코드가 아니에요
- 이 워크플로는 모든 언어에 통해요: JS, Python, Go, Ruby 등등
02 · 코드 예제
같은 요청을 curl, JavaScript (fetch), Python (requests) 세 가지로 작성해 봐요.
curl
curl https://api.github.com/users/torvalds \
-H "Accept: application/json"
JavaScript (fetch)
const response = await fetch('https://api.github.com/users/torvalds', {
headers: {
'Accept': 'application/json'
}
});
const data = await response.json();
console.log(data.name); // 'Linus Torvalds'
Python (requests)
import requests
response = requests.get(
'https://api.github.com/users/torvalds',
headers={'Accept': 'application/json'}
)
data = response.json()
print(data['name']) # Linus Torvalds
대응 관계를 봐요: - URL → 첫 번째 인자 - -H "Key: Value" → headers 객체 { 'Key': 'Value' } - -X POST → method: 'POST' - -d '{...}' → body: JSON.stringify({...}) 구조는 같아요. 문법만 달라요.
03 · 코드 예제
POST 요청 — 같은 데이터를 세 가지로 작성해 봐요.
curl
curl -X POST https://api.example.com/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer MY_TOKEN" \
-d '{"title": "Hello", "body": "World"}'
JavaScript (fetch)
const response = await fetch('https://api.example.com/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer MY_TOKEN'
},
body: JSON.stringify({ title: 'Hello', body: 'World' })
});
const data = await response.json();
Python (requests)
import requests
response = requests.post(
'https://api.example.com/posts',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer MY_TOKEN'
},
json={'title': 'Hello', 'body': 'World'}
)
data = response.json()
04 · 실기 실습
GitHub에서 microsoft 의 가장 최근 업데이트된 공개 repo 3 개를 가져오는 curl 명령을 작성해요. 그런 다음 Claude Code 에 JavaScript 로 변환해 달라고 요청해요.
curl "https://api.github.com/users/microsoft/repos?sort=updated&per_page=3"
05 · 퀴즈
JavaScript fetch 로 변환할 때, curl 의 어떤 플래그가 'headers' 객체에 대응되나요?
- -H (header)
- -d (data)
- -X (method)
- -o (output)
06 · 빈칸 채우기
curl 플래그 -d '{"name": "test"}' 는 JavaScript fetch 옵션 객체에서 _____ 속성에 대응돼요.
07 · 프롬프트 템플릿
curl 이 동작하면 이 prompt 로 Claude Code 에게 코드로 변환해 달라고 요청해요.
이 curl 명령을 파싱된 JSON 을 반환하는 JavaScript async 함수로 변환해 줘:
curl "https://api.github.com/users/microsoft/repos?sort=updated&per_page=3"
함수 이름은 `getMicrosoftRepos` 로 하고 오류를 적절히 처리해 줘.
08 · 퀴즈
JavaScript fetch 에서 어떤 속성이 curl 의 -d 플래그를 대체하나요?
09 · 빈칸 채우기
curl 플래그 -H "Key: Value" 는 JavaScript fetch 호출에서 _____ 객체에 대응돼요.
⚠ 전체 인터랙티브 경험에는 JavaScript가 필요해요. JavaScript를 켜고 새로 고침해 주세요.
※ 이 사이트는 독립 운영되는 교육 프로젝트로, Anthropic의 공식 제품이 아니에요. Claude™ 는 Anthropic, PBC 의 상표예요.