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 | طلب POST مع بيانات JSON |
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 | مصادقة رمز حامل (Bearer token) |
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 proxy |
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 | فرض 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 | المصادقة الهضمية (Digest Authentication) |
| بناء الجملة | نوع | مثال |
|---|---|---|
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
حالة الاستخدام: تصحيح حموضات Webhook
--session=name
حالة الاستخدام: تنزيل ومعالجة بيانات API
:=
أفضل الممارسات
-
استخدم الجلسات للتدفقات المصادقة: تحتفظ الجلسات بملفات تعريف الارتباط والرؤوس، مما يلغي الحاجة لإعادة المصادقة لكل طلب. استخدم
age:=30للتفاعلات متعددة الخطوات مع API. -
استفد من التحويل التلقائي للأنواع في JSON: استخدم
active:=trueللأرقام والقيم المنطقية (xh POST api.com name=value,-v) بدلاً من القيم النصية لضمان أنواع JSON الصحيحة في طلبات API. -
فضّل xh على curl لاختبار API: بناء الجملة البديهي (
xh -a token:secret_key، استخدمxh -a token:$API_TOKENلتجنب كشف بيانات الاعتماد في سجل الأوامر. -
استخدم توجيه المخرجات للأتمتة: احفظ الاستجابات مع
-o file.jsonللمعالجة أو المقارنة في أنابيب CI/CD وسكريبتات الاختبار الآلي. -
ضع مهل زمنية مناسبة: استخدم
--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 |