curl is a command-line tool and library for transferring data across dozens of protocols — HTTP, HTTPS, FTP, SFTP, SMTP, and more — making it the universal Swiss Army knife for network operations. It is pre-installed on macOS and Windows 10+ and powers over 20 billion installations worldwide, from embedded devices to CI pipelines. Understanding the difference between curl's flag-heavy but precise syntax and the friendlier alternatives (HTTPie, wget) determines which tool fits each job: curl for scripting and API work, wget for recursive downloads, HTTPie for interactive API exploration.
What This Cheat Sheet Covers
This topic spans 16 focused tables and 116 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core HTTP Methods
Every REST API interaction maps to an HTTP verb; curl sends them all via -X or implied defaults.
| Command | Example | Description |
|---|---|---|
curl https://api.example.com/users | Default method — no -X flag needed; retrieves the resource at the URL. | |
curl -X POST -H "Content-Type: application/json" -d '{"name":"alice"}' https://api.example.com/users | Creates a new resource; -d implicitly sets method to POST and Content-Type to application/x-www-form-urlencoded unless overridden. | |
curl -X PUT -H "Content-Type: application/json" -d '{"name":"alice","age":30}' https://api.example.com/users/1 | Fully replaces the resource; must supply the complete representation. | |
curl -X PATCH -H "Content-Type: application/json" -d '{"age":31}' https://api.example.com/users/1 | Partially updates a resource — send only the fields that change. |