cURL HTTP and API Workflows

HTTP methods, auth, JSON APIs, headers, caching, compression, and response inspection with curl.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## HTTP Methods and APIs
GET JSON from an API
curl -H 'Accept: application/json' https://api.example.com/v1/items

# Fetch JSON and ask for a JSON response.

POST JSON
curl -X POST https://api.example.com/v1/items -H 'Content-Type: application/json' -d '{"name":"demo"}'

# Create a resource by sending JSON payload.

PUT JSON
curl -X PUT https://api.example.com/v1/items/123 -H 'Content-Type: application/json' -d '{"name":"updated"}'

# Replace a resource with a JSON request body.

PATCH JSON
curl -X PATCH https://api.example.com/v1/items/123 -H 'Content-Type: application/json' -d '{"status":"archived"}'

# Partially update a resource with JSON.

DELETE a resource
curl -X DELETE https://api.example.com/v1/items/123

# Delete a resource by ID.

Inspect allowed methods
curl -X OPTIONS -i https://api.example.com/v1/items

# Send an OPTIONS request to inspect server capabilities.

Send a TRACE request
curl -X TRACE -i https://example.com

# Use TRACE for debugging if the server allows it.

Send custom content type
curl -X POST https://api.example.com/import -H 'Content-Type: application/xml' --data-binary @payload.xml

# Post XML or another custom media type.

## HTTP Auth and Security
HTTP Basic auth
curl -u 'user:password' https://example.com/protected

# Authenticate with username and password.

Bearer token auth
curl -H 'Authorization: Bearer TOKEN' https://api.example.com/me

# Send a Bearer token for OAuth-style APIs.

API key in header
curl -H 'x-api-key: YOUR_API_KEY' https://api.example.com/data

# Send an API key header.

API key in query string
curl 'https://api.example.com/data?api_key=YOUR_API_KEY'

# Pass an API key in the URL.

Mutual TLS with client cert
curl --cert client.crt --key client.key https://mtls.example.com

# Authenticate using a client certificate and key.

Use a custom CA bundle
curl --cacert ca.pem https://internal.example.com

# Trust a specific CA certificate file.

Skip TLS certificate verification
curl -k https://selfsigned.example.com

# Disable certificate verification for testing only.

AWS SigV4 request signing
curl --aws-sigv4 'aws:amz:us-east-1:execute-api' --user 'AKIA...:SECRET' https://abc123.execute-api.us-east-1.amazonaws.com/prod/items

# Sign an AWS-compatible HTTP request using SigV4.

## Response Inspection
Request compressed response
curl --compressed https://example.com

# Ask the server for a compressed response body.

Save ETag metadata
curl --etag-save etag.txt -O https://example.com/data.json

# Store ETag metadata for conditional requests.

Conditional request with ETag
curl --etag-compare etag.txt -O https://example.com/data.json

# Use a saved ETag to avoid downloading unchanged content.

Conditional request by modification time
curl -z local-copy.txt -O https://example.com/local-copy.txt

# Only fetch if the remote file is newer than a local file.

Write headers to a file
curl -D headers.txt -o body.html https://example.com

# Store response headers separately from the body.

Verbose HTTP/TLS details
curl -v https://example.com

# Show detailed request and response conversation.

Full ASCII trace
curl --trace-ascii trace.txt https://example.com

# Capture a detailed ASCII trace of the transfer.

Multiple requests in one command
curl https://example.com --next -I https://api.example.com

# Separate different request groups with `--next`.

Recommended next

No recommendations yet.