curl-http

📁 1mangesh1/dev-skills-collection 📅 6 days ago
4
总安装量
4
周安装量
#51701
全站排名
安装命令
npx skills add https://github.com/1mangesh1/dev-skills-collection --skill curl-http

Agent 安装分布

opencode 4
gemini-cli 4
github-copilot 4
codex 4
kimi-cli 4
cursor 4

Skill 文档

curl & HTTPie

Command-line HTTP clients for API testing.

curl Basics

GET Request

curl https://api.example.com/users
curl -s https://api.example.com/users  # Silent
curl -i https://api.example.com/users  # Include headers

POST Request

# JSON body
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"John","email":"john@example.com"}'

# From file
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d @data.json

Headers & Auth

# Custom header
curl -H "Authorization: Bearer token123" https://api.example.com

# Basic auth
curl -u username:password https://api.example.com

# Multiple headers
curl -H "Content-Type: application/json" \
     -H "X-API-Key: key123" \
     https://api.example.com

Other Methods

# PUT
curl -X PUT https://api.example.com/users/1 \
  -H "Content-Type: application/json" \
  -d '{"name":"Updated"}'

# PATCH
curl -X PATCH https://api.example.com/users/1 \
  -d '{"status":"active"}'

# DELETE
curl -X DELETE https://api.example.com/users/1

File Upload

# Form upload
curl -X POST https://api.example.com/upload \
  -F "file=@photo.jpg" \
  -F "description=My photo"

# Binary
curl -X POST https://api.example.com/upload \
  --data-binary @file.bin \
  -H "Content-Type: application/octet-stream"

Useful Options

-v          # Verbose (debug)
-s          # Silent
-o file     # Output to file
-O          # Save with remote filename
-L          # Follow redirects
-k          # Ignore SSL errors
-w '\n'     # Add newline after output
--max-time 10  # Timeout in seconds

HTTPie (Friendlier Alternative)

GET Request

http https://api.example.com/users
http GET api.example.com/users  # Explicit GET

POST Request

# JSON (default)
http POST api.example.com/users name=John email=john@example.com

# String vs other types
http POST api.example.com/users name=John age:=30 active:=true

Headers & Auth

# Header
http api.example.com Authorization:"Bearer token"

# Basic auth
http -a user:pass api.example.com

# Bearer auth
http api.example.com "Authorization: Bearer token"

Output Control

http -h api.example.com   # Headers only
http -b api.example.com   # Body only
http -p Hh api.example.com  # Request headers

Common Patterns

Test Response Code

# curl
status=$(curl -s -o /dev/null -w "%{http_code}" https://api.example.com)
echo "Status: $status"

# Check if successful
if curl -s -f https://api.example.com > /dev/null; then
  echo "Success"
fi

Pretty Print JSON

curl -s https://api.example.com | jq .
curl -s https://api.example.com | python -m json.tool

Save Response & Headers

curl -D headers.txt -o response.json https://api.example.com

Retry on Failure

curl --retry 3 --retry-delay 2 https://api.example.com

Timing Info

curl -w "Time: %{time_total}s\n" -o /dev/null -s https://api.example.com

GraphQL

curl -X POST https://api.example.com/graphql \
  -H "Content-Type: application/json" \
  -d '{"query": "{ users { id name } }"}'

Debug

# Verbose output
curl -v https://api.example.com

# Trace (very detailed)
curl --trace - https://api.example.com

# Show only response headers
curl -I https://api.example.com