Linux/macOS
| 플랫폼 | 명령어 |
|---|---|
| Ubuntu/Debian | `curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh \ |
| Arch Linux | pacman -S xh |
| Fedora/RHEL | dnf 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 |
| Docker | docker pull ducaale/xh |
| Snap | snap install xh |
| 명령어 | 설명 |
|---|---|
xh httpbin.org/get | 간단한 GET 요청 |
xh POST httpbin.org/post name=John | JSON 데이터를 사용한 POST 요청 |
xh PUT httpbin.org/put status=active | PUT 요청과 데이터 |
xh PATCH httpbin.org/patch email=new@email.com | PATCH 요청으로 리소스 업데이트하기 |
xh DELETE httpbin.org/delete | DELETE 요청 |
xh HEAD httpbin.org/get | HEAD 요청 (헤더만) |
xh OPTIONS httpbin.org/get | OPTIONS 요청 |
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=John | POST로 폼 데이터 전송 |
xh POST httpbin.org/post < data.json | 파일 내용으로 POST |
xh httpbin.org/get Authorization:"Bearer token" | 인증 헤더 |
| 명령어 | 설명 |
|---|---|
xh POST httpbin.org/post age:=30 active:=true | JSON 타입 강제 변환 (숫자/부울) |
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/get | HTTP 프록시 사용 |
xh --proxy=all:socks5://localhost:1080 httpbin.org/get | SOCKS5 프록시 사용 |
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/get | Force 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:=null | Null | middle:=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 failed | Use --verify=no to skip verification (insecure) or --cert=/path/to/ca.pem to provide custom CA certificate |
Connection timeout | Increase timeout with --timeout=60 or check network connectivity and proxy settings |
401 Unauthorized | Verify authentication method: use -a user:pass for basic auth, -A bearer -a token for bearer tokens, or check session validity |
JSON parsing error | Ensure proper syntax: use := for non-strings (age:=30), quote arrays (tags:='["a","b"]'), and check for unescaped special characters |
Command not found: xh | Verify installation path is in $PATH, reinstall using preferred method, or use full path /usr/local/bin/xh |
Session not persisting | Check session directory permissions (~/.config/xh/sessions/), ensure using same session name, verify not using --session-read-only |
Proxy connection failed | Verify proxy URL format --proxy=http:http://host:port, check proxy authentication if required, ensure proxy allows target host |
File upload fails | Use -f or --multipart flag for form uploads, verify file path is correct, check file permissions and size limits |
Response not formatted/colored | Force formatting with --pretty=all, check terminal supports colors, or pipe through jq for JSON formatting |