Intermediate · 10 min · practise every command in the built-in terminal

curl — Transfer Data with URLs

curl is the Swiss Army knife of HTTP requests.

Basic GET request

curl https://httpbin.org/get
curl -s https://api.ipify.org          # -s = silent (no progress)

Save to file

curl -o output.html https://example.com
curl -O https://example.com/file.zip   # Use remote filename

POST request

curl -X POST -d 'name=IVski&email=test@test.com' https://httpbin.org/post
curl -X POST -H 'Content-Type: application/json' \
     -d '{"name":"IVski"}' https://httpbin.org/post

Headers

curl -I https://example.com                # Headers only (HEAD)
curl -v https://example.com               # Verbose: all headers
curl -H 'Authorization: Bearer TOKEN' URL
curl -H 'User-Agent: MyBot/1.0' URL

Authentication

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

Follow redirects

curl -L https://short.url    # Follow redirects

Practical examples

# Check your public IP
curl -s https://api.ipify.org

# Download a file with progress
curl -# -O https://example.com/file.zip

# Test an API
curl -s https://jsonplaceholder.typicode.com/posts/1 | python3 -m json.tool

Practice tasks

  1. Fetch the headers of https://example.com
  2. Fetch the full HTML body of https://example.com
  3. Save the response of a request to a file instead of printing it

Commands in this lesson

Networking