コンテンツにスキップ

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.comリソースを更新するための PATCH リクエスト
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=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:=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\
```## 設定

### セッションストレージの場所
```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
```### 一般的なエイリアス
```bash
# 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
```## 一般的なユースケース

### ユースケース:認証付きREST APIのテスト
```bash
# 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"
```### ユースケース:メタデータ付きファイルアップロード
```bash
# 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
```### ユースケース:異なる環境でのAPI テスト
```bash
# 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
```### ユースケース:Webhookペイロードのデバッグ
```bash
# 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
```### ユースケース:APIデータのダウンロードと処理
`--session=name`セッション
`:=`JSON型強制
`age:=30`true
`active:=true`false
`xh POST api.com name=value`xh get https://api.example.com/users
`-v`-v

Would you like me to elaborate on any part of the translation?`xh -a token:secret_key`、使用`xh -a token:$API_TOKEN`を使用して、シェル履歴に資格情報を公開しないようにします。

- **出力リダイレクションを活用する**: レスポンスを保存 `-o file.json`でCI/CDパイプラインや自動テストスクリプトでの処理や比較に使用します。

- **適切なタイムアウトを設定する**: 遅い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 || `HTTP/2 not working`| サーバーがHTTP/2をサポートしているか確認し、OpenSSL/TLSが適切に設定されているか確認し、比較するために `--http-version=1.1`でHTTP/1.1を強制的に使用してみてください |