Learn curl

Command-line tool for making HTTP and other URL requests

14 lessons · 2 hours · 4 levels · covers curl 8.16

curl transfers data to and from URLs from the command line, supporting HTTP(S) and dozens of other protocols. Developers use it to test and debug APIs, download files, script integrations and reproduce requests exactly, and its library libcurl powers networking in countless applications and devices.

Before you start

curl builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics4 lessons · 36 min in total
2. PracticalUse it productively at work, with the usual idioms8 lessons · 1 hour in total
3. AdvancedThe less common features, performance and trade-offs11 lessons · 2 hours in total
4. ExpertInternals and the edge cases experts know14 lessons · 2 hours in total

The curl tree

curlYour first requests: GET and downloadsYour first requests:GET and downloadsSeeing headers: -i, -I, -v and -HSeeing headers: -i, -I,-v and -HPOST, PUT and forms: -d, -X, -FPOST, PUT andforms: -d, -X, -FJSON APIs and authenticationJSON APIs andauthenticationFailing properly: --fail and exit codesFailing properly: --failand exit codesMeasuring with --write-outMeasuring with--write-outCookies and login sessionsCookies and loginsessionsTimeouts and retriesTimeouts and retries
Essentials and Practical shown (8 of 14 lessons); the full list is below. Click a lesson to read it.

All 14 lessons, in order

First requests

  1. Your first requests: GET and downloads · Essentials · 7 min

    curl URL prints the response body; -o and -O save it to a file, -L follows redirects and -s hides the progress meter.

  2. Seeing headers: -i, -I, -v and -H · Essentials · 9 min

    Show response headers with -i, send a HEAD request with -I, see the full exchange with -v and add request headers with -H.

Sending data and auth

  1. POST, PUT and forms: -d, -X, -F · Essentials · 10 min

    Send form data with -d, change the method with -X, upload files as multipart with -F and URL-encode safely with --data-urlencode.

  2. JSON APIs and authentication · Essentials · 10 min

    Call JSON APIs with --json, authenticate with bearer tokens or -u for basic auth, and pipe responses into jq.

  3. Cookies and login sessions · Practical · 8 min

    Store cookies with -c, send them with -b and script login flows that need a session cookie.

Inspecting and failing well

  1. Failing properly: --fail and exit codes · Practical · 9 min

    By default curl exits 0 even on HTTP 404 or 500; use --fail or --fail-with-body and check exit codes in scripts.

  2. Measuring with --write-out · Practical · 10 min

    Print status codes, timings, sizes or a full JSON summary after a transfer with -w and its %{variables}.

Scripting with curl

  1. Timeouts and retries · Practical · 9 min

    Bound how long curl waits with --connect-timeout and --max-time, and retry transient failures with --retry.

  2. Config files and --variable · Advanced · 12 min

    Keep options and secrets out of the command line with -K config files, and template headers and bodies with --variable and --expand.

  3. URL globbing and parallel transfers · Advanced · 10 min

    Fetch many URLs in one command with [1-100] and {a,b} globs, name outputs with #1, and run transfers concurrently with -Z.

TLS, protocols and libcurl

  1. TLS, certificates and host overrides · Advanced · 12 min

    Control certificate verification with --cacert, use client certificates for mTLS, and test servers with --resolve and --connect-to.

  2. HTTP/2, HTTP/3 and connection behaviour · Expert · 12 min

    See how curl negotiates HTTP/1.1, HTTP/2 and HTTP/3, force a version for testing, and understand reuse and Alt-Svc.

  3. Tracing, proxies and name resolution · Expert · 12 min

    Dump exact bytes with --trace-ascii, route traffic through proxies with -x and proxy env vars, and debug DNS with --dns-servers and -4/-6.

  4. libcurl: curl as a library · Expert · 12 min

    libcurl is the C library behind curl, with easy and multi interfaces, bindings for most languages and --libcurl to generate code.