cURL Cheatsheet

Complete cURL cheatsheet covering HTTP requests, authentication, SSL, data transfer, and advanced options for command-line web interactions.

cURL Cheatsheet

cURL

HTTP

API

Web Tools

Complete reference for cURL commands, from basic HTTP requests to advanced data transfer, authentication, and performance monitoring.

Quick Reference

🌐 Basic Requests

Essential HTTP GET, POST, PUT, DELETE operations

🔐 Authentication

Basic auth, tokens, and SSL certificate handling

📊 Data Transfer

Upload, download, and file operations

📈 Performance

Timing, debugging, and output formatting

Basic Commands

Help and Information

Show help

curl -h

Show detailed help

curl --help

Show manual page

curl --manual

Verbose Output

Enable verbose output

curl -v

Enable extra verbose output

curl -vv

Basic Requests

Simple GET request

curl http://example.com

Display response headers only

curl -I http://example.com

Follow redirects

curl -L http://example.com

File Operations

Download Files

Redirect output to file

curl http://url/file > file

Write to specific file

curl -o filename http://url/file

Write to file with same name as remote

curl -O http://url/file

Download multiple files

curl -O http://url/file1 -O http://url/file2

Execute Remote Scripts

Execute remote bash script

bash <(curl -s http://url/script.sh)

HTTP Methods

GET Requests

Explicit GET request

curl -X GET http://example.com/api/data

GET with query parameters

curl "http://example.com/api/search?q=term&limit=10"

POST Requests

POST with JSON data

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"key":"value"}' \
  http://example.com/api

POST with form data

curl -X POST \
  -d "name=value&email=test@example.com" \
  http://example.com/form

POST data from file

curl -X POST \
  -d @data.json \
  -H "Content-Type: application/json" \
  http://example.com/api

PUT Requests

PUT with data

curl -X PUT \
  -H "Content-Type: application/json" \
  -d '{"key":"value"}' \
  http://example.com/api/resource

DELETE Requests

DELETE request

curl -X DELETE http://example.com/api/resource/123

Authentication

cURL supports various authentication methods for secure API access.

Basic Authentication

Basic auth with username and password

curl -u username:password http://example.com/protected

Basic auth with prompt for password

curl -u username http://example.com/protected

Bearer Token Authentication

Authorization header with bearer token

curl -H "Authorization: Bearer your_token_here" http://example.com/api

API Key Authentication

API key in header

curl -H "X-API-Key: your_api_key" http://example.com/api

API key in query parameter

curl "http://example.com/api?api_key=your_api_key"

SSL and Security

Use SSL options carefully in production environments.

SSL Certificate Handling

Ignore SSL certificate errors

curl -k https://self-signed-cert.example.com

Specify CA certificate

curl --cacert ca-cert.pem https://example.com

Use client certificate

curl --cert client.pem \
  --key client-key.pem \
  https://example.com

Headers and Cookies

Custom Headers

Add custom header

curl -H "User-Agent: MyApp/1.0" http://example.com

Multiple custom headers

curl -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  http://example.com

Remove default header

curl -H "User-Agent:" http://example.com

Send cookies

curl -b "session=abc123; user=john" http://example.com

Save cookies to file

curl -c cookies.txt http://example.com

Load cookies from file

curl -b cookies.txt http://example.com

Advanced Options

Timeouts and Retries

Set connection timeout

curl --connect-timeout 10 http://example.com

Set maximum time for operation

curl --max-time 30 http://example.com

Retry on failure

curl --retry 3 --retry-delay 2 http://example.com

Proxy Settings

Use HTTP proxy

curl --proxy http://proxy.example.com:8080 \
  http://example.com

Use SOCKS proxy

curl --socks5 proxy.example.com:1080 http://example.com

Performance Monitoring

Use write-out options to monitor request performance and debug issues.

Basic Performance Metrics

Show response code

curl -w "%{response_code}\n" -s -o /dev/null http://example.com

Show total time

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

Show download speed

curl -w "%{speed_download}\n" -s -o /dev/null http://example.com

Detailed Timing Information

Complete timing breakdown

curl -w "namelookup: %{time_namelookup}\n\
connect: %{time_connect}\n\
appconnect: %{time_appconnect}\n\
pretransfer: %{time_pretransfer}\n\
redirect: %{time_redirect}\n\
starttransfer: %{time_starttransfer}\n\
total: %{time_total}\n" \
-s -o /dev/null http://example.com

Size information

curl -w "size_download: %{size_download}\n\
size_upload: %{size_upload}\n\
size_header: %{size_header}\n" \
-s -o /dev/null http://example.com

Write-Out Format Variables

Response Information

Content type

curl -w "%{content_type}" -s -o /dev/null http://example.com

Response code

curl -w "%{response_code}" -s -o /dev/null http://example.com

Effective URL

curl -w "%{url_effective}" -s -o /dev/null http://example.com

Network Information

Remote IP address

curl -w "%{remote_ip}" -s -o /dev/null http://example.com

Local IP address

curl -w "%{local_ip}" -s -o /dev/null http://example.com

Number of redirects

curl -w "%{num_redirects}" -s -o /dev/null http://example.com

Configuration

Config File

Use config file

curl -K config.txt

Default config file location

# ~/.curlrc (Unix-like systems)

Sample config file content

# Sample .curlrc
user-agent = "MyApp/1.0"
connect-timeout = 10
max-time = 30

Best Practices

Follow these cURL best practices for reliable and secure HTTP operations.

  • Use HTTPS whenever possible for secure communication
  • Set timeouts to prevent hanging requests
  • Handle errors by checking response codes
  • Use config files for repeated options
  • Validate SSL certificates in production
  • Log requests for debugging and monitoring
  • Use appropriate HTTP methods (GET, POST, PUT, DELETE)
  • Include proper headers for API compatibility

Learn More

Explore comprehensive cURL documentation

Written by

Deepak Jangra

Created At

Wed Jan 15 2025

Updated At

Fri Jun 13 2025

Cheatsheets

Your go-to resource for quick reference guides on essential development tools and technologies.

© 2025 Deepak Jangra. All rights reserved.