Home/Engineer/Networking / Servers/curl · wget Practical Guide …
Networking / ServersBeginnerUbuntuDebianCentOSmacOScurlwgetapi

curl · wget Practical Guide — API Testing and File Downloads

How to test REST APIs with curl—including headers, authentication, and request bodies—how to download and mirror files with wget, and when to choose each tool.

Contents
  1. curl Basics
  2. HTTP Methods and Headers
  3. Authentication
  4. File Upload
  5. File Download
  6. wget Basics
  7. When to Choose curl vs wget

curl Basics

Bash
# GET request
curl https://api.example.com/users

# Pretty-print the response (paired with jq)
curl -s https://api.github.com/users/octocat | jq '.'

# Status code only
curl -o /dev/null -s -w "%{http_code}" https://example.com

# Verbose output (including headers)
curl -v https://example.com

# Headers only
curl -I https://example.com

# Follow redirects
curl -L https://example.com

# Timeouts
curl --connect-timeout 5 --max-time 30 https://example.com

HTTP Methods and Headers

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

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

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

# PATCH
curl -X PATCH https://api.example.com/users/1   -H "Content-Type: application/json"   -d '{"email":"new@example.com"}'

# Multiple headers
curl https://api.example.com   -H "Accept: application/json"   -H "X-Request-ID: abc123"   -H "User-Agent: MyScript/1.0"

Authentication

Bash
# Bearer token
curl -H "Authorization: Bearer eyJhbGci..." https://api.example.com/me

# Basic Auth
curl -u username:password https://api.example.com
# or
curl -H "Authorization: Basic $(echo -n user:pass | base64)" https://api.example.com

# API key
curl -H "X-API-Key: your-api-key" https://api.example.com

# Cookies
curl -b "session=abc123; token=xyz" https://example.com

# Save and send cookies
curl -c cookies.txt https://example.com/login -d "user=admin&pass=1234"
curl -b cookies.txt https://example.com/dashboard

File Upload

Bash
# Form file upload (multipart)
curl -F "file=@/path/to/file.pdf" https://api.example.com/upload
curl -F "file=@image.jpg;type=image/jpeg" -F "name=profile" https://example.com

# Raw binary data
curl -X PUT --data-binary @file.tar.gz https://example.com/upload

File Download

Bash
# Save file (-O: original filename, -o: specified filename)
curl -O https://example.com/file.tar.gz
curl -o myfile.tar.gz https://example.com/file.tar.gz

# Show progress
curl -# -O https://example.com/large-file.iso

# Resume (interrupted download)
curl -C - -O https://example.com/large-file.iso

# Parallel downloads (with xargs)
cat urls.txt | xargs -n1 -P4 curl -O

wget Basics

Bash
# Download a file
wget https://example.com/file.tar.gz

# Resume download
wget -c https://example.com/large-file.iso

# Quiet (no progress)
wget -q https://example.com/file.tar.gz

# Number of retries
wget --tries=5 https://example.com/file.tar.gz

# Save under a specific filename
wget -O myfile.tar.gz https://example.com/file

# Recursive download (site mirroring)
wget -r -np -nH --cut-dirs=1 https://example.com/docs/

# Specific file types only
wget -r -A "*.pdf" https://example.com/papers/

When to Choose curl vs wget

SituationRecommended
REST API testingcurl
Custom HTTP methods/headerscurl
File download (resume)wget
Site mirroringwget
API calls in scriptscurl
FTP file downloadcurl
#curl#wget#api#http
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Questions & answers

Ask a question about this guide. We'll review and reply.