콘텐츠로 이동

Linux/macOS

플랫폼명령어
Ubuntu/Debian`curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh \
Arch Linuxpacman -S xh
Fedora/RHELdnf install xh
macOS (Homebrew)brew install xh
macOS (MacPorts)sudo port install xh
Windows (Scoop)scoop install xh
Windows (Chocolatey)choco install xh
Cargo (All platforms)cargo install xh
Dockerdocker pull ducaale/xh
Snapsnap install xh
명령어설명
xh httpbin.org/get간단한 GET 요청
xh POST httpbin.org/post name=JohnJSON 데이터를 사용한 POST 요청
xh PUT httpbin.org/put status=activePUT 요청과 데이터
xh PATCH httpbin.org/patch email=new@email.comPATCH 요청으로 리소스 업데이트하기
xh DELETE httpbin.org/deleteDELETE 요청
xh HEAD httpbin.org/getHEAD 요청 (헤더만)
xh OPTIONS httpbin.org/getOPTIONS 요청
xh httpbin.org/get search==rust쿼리 매개변수와 함께 GET
xh httpbin.org/get page==1 limit==10여러 쿼리 매개변수
xh -a user:pass httpbin.org/basic-auth/user/pass기본 인증
xh -A bearer -a token123 api.example.com베어러 토큰 인증
xh httpbin.org/get User-Agent:CustomAgent사용자 지정 헤더
xh -b httpbin.org/json응답 본문만 출력
xh -h httpbin.org/json응답 헤더만 출력
xh -v httpbin.org/json자세한 출력 (헤더 + 본문)
xh httpbin.org/json -o response.json파일에 응답 다운로드
xh --follow=0 httpbin.org/redirect/3리다이렉트를 따르지 마세요
xh -f POST httpbin.org/post name=JohnPOST로 폼 데이터 전송
xh POST httpbin.org/post < data.json파일 내용으로 POST
xh httpbin.org/get Authorization:"Bearer token"인증 헤더
명령어설명
xh POST httpbin.org/post age:=30 active:=trueJSON 타입 강제 변환 (숫자/부울)
xh POST httpbin.org/post tags:='["rust","cli"]'JSON 배열 보내기
xh POST httpbin.org/post user[name]=John user[age]:=30중첩된 JSON 객체
xh --session=mysession httpbin.org/cookies/set/token/abc명명된 세션 생성 (쿠키 유지)
xh --session=mysession httpbin.org/cookies세션 재사용
xh --session-read-only=mysession httpbin.org/get세션을 업데이트하지 않고 사용하기
xh -f POST httpbin.org/post file@/path/to/file.txt다중 파트 양식으로 파일 업로드
xh POST httpbin.org/post @file.json요청 본문으로 파일 업로드
xh --proxy=http:http://proxy.example.com:8080 httpbin.org/getHTTP 프록시 사용
xh --proxy=all:socks5://localhost:1080 httpbin.org/getSOCKS5 프록시 사용
xh --verify=no https://self-signed.badssl.com/SSL 확인 건너뛰기 (안전하지 않음)
xh --cert=/path/to/ca-cert.pem https://api.example.com사용자 정의 CA 인증서
xh --cert=/path/to/client.crt --cert-key=/path/to/client.key https://api.example.com클라이언트 인증서 인증
xh --timeout=30 httpbin.org/delay/5요청 시간 초과 설정 (초)
xh --pretty=none httpbin.org/json색상/서식 있는 출력 비활성화
xh --style=monokai httpbin.org/json특정 색상 구성표 사용
xh --stream httpbin.org/stream/100스트림 응답
xh --download httpbin.org/image/png -o image.png진행 표시줄과 함께 다운로드
xh --continue httpbin.org/stream/100 -o stream.txt이력서 부분 다운로드
xh --http-version=1.1 https://httpbin.org/getForce HTTP/1.1 강제
xh --method=CUSTOM httpbin.org/anything사용자 정의 HTTP 메서드
xh --multipart POST httpbin.org/post name=John file@doc.pdf혼합 데이터가 있는 멀티파트 양식
xh httpbin.org/get Cookie:session=abc123쿠키 보내기
xh --auth-type=digest -a user:pass httpbin.org/digest-auth/auth/user/pass다이제스트 인증
구문유형예시
key=value문자열name=John{"name":"John"}
key:=number숫자age:=30{"age":30}
key:=true부울active:=true{"active":true}
key:=nullNullmiddle:=null{"middle":null}
key:='[...]'배열tags:='["a","b"]'{"tags":["a","b"]}
key:='{...}'객체meta:='{"v":1}'{"meta":{"v":1}}
key[sub]=value중첩된user[name]=John{"user":{"name":"John"}}
# Linux/macOS
~/.config/xh/sessions/

# Windows
%APPDATA%\xh\sessions\
```## JSON 데이터 타입

JSON 데이터를 보낼 때, xh는 특수 구문으로 타입 강제 변환을 지원합니다:
```bash
# Set default proxy
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080

# Disable proxy for specific hosts
export NO_PROXY=localhost,127.0.0.1,.example.com

# Default timeout
export XH_TIMEOUT=30
```## 구성

### 세션 저장 위치
```bash
# Add to ~/.bashrc or ~/.zshrc

# HTTPie compatibility
alias http='xh'
alias https='xh --default-scheme=https'

# Quick shortcuts
alias xhj='xh --pretty=all'  # Force JSON pretty-print
alias xhn='xh --pretty=none' # No formatting
alias xhv='xh -v'            # Verbose by default
alias xhd='xh --download'    # Download mode

환경 변수

# Login and save session
xh --session=api POST https://api.example.com/login \
  username=admin password=secret

# Make authenticated requests using saved session
xh --session=api GET https://api.example.com/users

# Update resource
xh --session=api PUT https://api.example.com/users/123 \
  name="John Doe" email=john@example.com status=active

# Delete resource
xh --session=api DELETE https://api.example.com/users/123

공통 별칭

# Upload file with additional form fields
xh -f POST https://api.example.com/upload \
  file@/path/to/document.pdf \
  title="Important Document" \
  category=legal \
  tags:='["contract","2024"]'

# Multiple file upload
xh -f POST https://api.example.com/batch-upload \
  file1@image1.jpg \
  file2@image2.jpg \
  album="Vacation 2024"

일반적인 사용 사례

사용 사례: 인증을 통한 REST API 테스트

# Development environment
xh --session=dev POST https://dev-api.example.com/test \
  Authorization:"Bearer dev-token-123" \
  data=test

# Staging environment
xh --session=staging POST https://staging-api.example.com/test \
  Authorization:"Bearer staging-token-456" \
  data=test

# Production environment (with SSL verification)
xh --session=prod POST https://api.example.com/test \
  Authorization:"Bearer prod-token-789" \
  data=test

사용 사례: 메타데이터와 함께 파일 업로드

# Capture webhook payload to file
xh POST https://webhook.site/your-unique-url \
  event=user.created \
  user[id]:=12345 \
  user[email]=new@example.com \
  timestamp:=$(date +%s) \
  -v -o webhook-debug.txt

# Test webhook with retry logic (in script)
for i in {1..3}; do
  xh POST https://your-app.com/webhook \
    event=test \
    attempt:=$i && break || sleep 5
done

사용 사례: 다른 환경에서의 API 테스트

# Download JSON data
xh GET https://api.github.com/users/octocat/repos \
  -o repos.json

# Download with authentication and save
xh -a token:ghp_your_token \
  GET https://api.github.com/user/repos \
  visibility==private \
  -o private-repos.json

# Stream large dataset
xh --stream GET https://api.example.com/export/data \
  format==json \
  | jq '.[] | select(.active == true)' \
  > active-records.json

사용 사례: 웹훅 페이로드 디버깅

--session=name

사용 사례: API 데이터 다운로드 및 처리

:=

모범 사례

  • 인증된 워크플로우에 세션 사용: 세션은 쿠키와 헤더를 유지하여 각 요청마다 다시 인증할 필요가 없습니다. 다단계 API 상호작용에 age:=30을 사용하세요.

  • JSON 타입 강제 변환 활용: 숫자와 부울 값에 active:=true을 사용하여 xh POST api.com name=value, -v과 같은 문자열 값 대신 API 요청에 올바른 JSON 타입을 보장하세요.

  • API 테스트에는 xh를 curl보다 선호: 직관적인 구문(xh -a token:secret_key, 사용xh -a token:$API_TOKEN셸 히스토리에 자격 증명이 노출되는 것을 방지하기 위해

  • 자동화를 위한 출력 리디렉션 활용: CI/CD 파이프라인 및 자동화된 테스트 스크립트에서 처리 또는 비교를 위해 -o file.json로 응답 저장

  • 적절한 타임아웃 설정: 느린 API에 대해 --timeout=30를 사용하여 요청이 멈추는 것을 방지합니다. 스트리밍 또는 장시간 실행되는 작업에 대해서만 --timeout=0를 설정합니다.

  • 환경별 세션 구성: 잘못된 자격 증명을 실수로 사용하는 것을 방지하기 위해 개발, 스테이징, 프로덕션(--session=prod-api)에 대해 별도의 세션 생성

문제 해결

문제솔루션
SSL certificate verification failedUse --verify=no to skip verification (insecure) or --cert=/path/to/ca.pem to provide custom CA certificate
Connection timeoutIncrease timeout with --timeout=60 or check network connectivity and proxy settings
401 UnauthorizedVerify authentication method: use -a user:pass for basic auth, -A bearer -a token for bearer tokens, or check session validity
JSON parsing errorEnsure proper syntax: use := for non-strings (age:=30), quote arrays (tags:='["a","b"]'), and check for unescaped special characters
Command not found: xhVerify installation path is in $PATH, reinstall using preferred method, or use full path /usr/local/bin/xh
Session not persistingCheck session directory permissions (~/.config/xh/sessions/), ensure using same session name, verify not using --session-read-only
Proxy connection failedVerify proxy URL format --proxy=http:http://host:port, check proxy authentication if required, ensure proxy allows target host
File upload failsUse -f or --multipart flag for form uploads, verify file path is correct, check file permissions and size limits
Response not formatted/coloredForce formatting with --pretty=all, check terminal supports colors, or pipe through jq for JSON formatting