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

HTTPie — 더 친절한 HTTP

~8 min · httpie, http, alternative

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

HTTPie 의 자리

curl 은 스크립팅에 무적. HTTPie 는 손으로 API 탐색할 때 짧은 문법, JSON 인식, syntax-highlight 출력. brew install httpie.

합리적 default

http https://api.github.com/users/cli
# = curl -sS -H 'Accept: application/json' https://...

JSON 친화 Accept 헤더 default, redirect 덜 공격적으로 따라감, JSON 색깔 출력. 출력이 문서처럼 읽힘.

30 초 안에 POST

http POST https://api.example/items name=pippa qty:=3 active:=true

해석: 'JSON body {name: "pippa", qty: 3, active: true} 로 POST.' := 가 비문자열 (숫자, bool). 그냥 = 는 문자열. JSON 직접 인용할 필요 없음.

헤더 / auth / 파일

  • http GET https://... 'Authorization: Bearer xyz'
  • http -a user:pass GET https://...
  • http POST https://... < body.json — stdin 의 파일을 body 로.
  • http --download https://.../file.zip — progress bar + 파일명 자동.

Session

http --session=mysession POST https://api/login user=alice pass=... 이 쿠키 / 헤더 / basic auth 저장. 이후 http --session=mysession ... 가 재사용. 다단계 API 탐색에 좋음.

curl 이 여전히 이기는 곳

Python 없는 미니멀 컨테이너용 스크립트. 성능 중요 루프. 이미 curl 쓰는 도구. 그 외, 특히 프롬프트에서, HTTPie 가 친절한 default.

Code

비교·bash
# curl version
curl -sS -X POST https://httpbin.org/post \
  -H 'Content-Type: application/json' \
  -d '{"name":"pippa","qty":3}'
# httpie version
http POST https://httpbin.org/post name=pippa qty:=3

External links

Exercise

httpie 설치: brew install httpie. http GET https://api.github.com/users/cli. http POST https://httpbin.org/post name=pippa qty:=3 active:=true 후 JSON echo 확인.

Progress

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

댓글 0

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

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