curl Command Builder
Build curl commands from method, headers, and body
Generated cURL Command
curl \ -L \ 'https://api.example.com/users'
Request
Headers
Authentication
Options
Quick Templates
The curl Command Builder generates complete, properly escaped curl commands through an interactive form, letting you configure HTTP method, headers, authentication, request body, and options without memorizing curl's extensive flag syntax. Select POST, add a JSON body and Bearer token, and get a ready-to-paste command like curl -X POST -H "Authorization: Bearer eyJ..." -H "Content-Type: application/json" -d '{"name":"Alice"}' https://api.example.com/users.
Understanding curl
curl is the Swiss Army knife of HTTP. It ships with virtually every Linux distribution, every macOS installation, and is available on Windows. When you need to test an API endpoint, reproduce a bug report, check response headers, or verify that a server is reachable, curl is usually the fastest path from question to answer. It runs in any terminal, requires no setup, and produces output you can pipe into other tools, save to files, or include in scripts.
The challenge with curl is its sheer breadth. The tool supports over 200 command-line flags, covering everything from basic GET requests to client certificate authentication, proxy tunneling, and resumable downloads. For everyday API testing, you need maybe a dozen of these flags, but knowing which ones and getting the syntax right -- especially quoting rules that differ between bash, zsh, PowerShell, and CMD -- takes practice. It is easy to forget whether the authentication flag is -u or --user, whether the body goes after -d or --data, and whether JSON bodies need single quotes or escaped double quotes.
This builder handles the syntax for you. You fill in the parts you know -- URL, method, headers, body, auth credentials -- and it generates a correctly formatted, properly escaped command for your platform. You can copy it directly to your terminal and run it. Over time, building commands interactively and studying the output is one of the best ways to learn curl's syntax, because you can see how each form field maps to a flag and how the quoting works for your shell.
How to Build a curl Command
- Enter the target URL for your HTTP request.
- Select the HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS).
- Add custom headers (e.g.,
Content-Type: application/json,Authorization: Bearer <token>). - Set the request body for POST/PUT/PATCH requests (JSON, form data, or raw text).
- Configure options like follow redirects, timeout, or verbose output.
- Copy the generated command for your shell (Unix/macOS or Windows PowerShell).
curl Command Examples
Simple GET Request
curl https://api.example.com/users/42
POST Request with JSON Body
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "[email protected]", "role": "admin"}'
Authenticated Request with Bearer Token
curl https://api.example.com/account \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
PUT Request with Basic Auth
curl -X PUT https://api.example.com/settings \
-u "admin:password123" \
-H "Content-Type: application/json" \
-d '{"notifications": true, "theme": "dark"}'
POST Form Data (URL-Encoded)
curl -X POST https://example.com/login \
-d "username=alice&password=secret123"
Request with Multiple Options
curl -X DELETE https://api.example.com/posts/99 \
-H "Authorization: Bearer eyJhbGci..." \
-H "X-Request-ID: req-abc-123" \
-L \
--max-time 30 \
-w "\n%{http_code}\n"
When to Use the curl Command Builder
- Testing APIs during development -- Quickly construct requests to test endpoints without writing client code or switching to a GUI tool.
- Generating documentation examples -- Build correct, copy-paste-ready curl commands for API documentation and README files.
- Creating reproducible bug reports -- Generate a standalone curl command that reproduces an issue, making it easy for other developers to test.
- Learning curl syntax -- Build commands interactively and study the generated flags to learn curl's options by example.
- Cross-platform command generation -- Get properly escaped commands for both Unix/macOS shells (using single quotes) and Windows PowerShell (using escaped double quotes).
- Sharing API test cases -- Produce a self-contained command that anyone with curl can run to verify behavior.
curl Flag Reference
Common Flags
| Flag | Long Form | Purpose | Example |
|---|---|---|---|
-X | --request | Set HTTP method | -X POST |
-H | --header | Add custom header | -H "Content-Type: application/json" |
-d | --data | Send request body | -d '{"key": "value"}' |
-u | --user | Basic authentication | -u "user:pass" |
-L | --location | Follow redirects | -L |
-o | --output | Write output to file | -o response.json |
-s | --silent | Suppress progress bar | -s |
-v | --verbose | Show request/response headers | -v |
-k | --insecure | Skip TLS verification | -k |
-w | --write-out | Custom output format | -w "%{http_code}" |
Timeout and Retry Flags
| Flag | Purpose | Example |
|---|---|---|
--max-time | Total time limit in seconds | --max-time 30 |
--connect-timeout | Connection timeout in seconds | --connect-timeout 5 |
--retry | Number of retries on failure | --retry 3 |
--retry-delay | Seconds between retries | --retry-delay 2 |
Body and Content Flags
| Flag | Purpose | When to Use |
|---|---|---|
-d / --data | Send data as request body | JSON, form data, raw text |
--data-raw | Send data without @ interpretation | When body contains @ characters |
--data-binary | Send binary data as-is | File uploads, binary payloads |
-F / --form | Send multipart form data | File uploads with form fields |
--data-urlencode | URL-encode the data before sending | Form data with special characters |
Shell Escaping and Quoting
The builder handles the tricky differences between shells:
Unix/macOS (bash, zsh) -- Uses single quotes for JSON bodies to avoid interpreting $ and !:
curl -d '{"price": "$9.99"}' https://api.example.com/order
Windows PowerShell -- Uses escaped double quotes since PowerShell does not support single-quoted string interpolation the same way:
curl -d "{\"price\": \"$9.99\"}" https://api.example.com/order
Windows CMD -- Uses double quotes with escaped inner quotes:
curl -d "{\"price\": \"$9.99\"}" https://api.example.com/order
Practical Tips for Using curl
One of the most useful but underused curl features is the -w (write-out) flag. It lets you print specific information about the request after it completes, such as the HTTP status code, total time, DNS resolution time, or the size of the response. For quick API testing, curl -s -o /dev/null -w "%{http_code}\n" https://api.example.com/health gives you just the status code with no body output -- perfect for health check scripts. You can also use -w "%{time_total}\n" to measure response times from the command line without installing additional tools.
When debugging SSL/TLS issues, curl's -v (verbose) flag shows the entire TLS handshake including the certificate chain, protocol version, and cipher suite. This is invaluable for diagnosing certificate errors, testing certificate rotation, or verifying that a server supports a specific TLS version. Pair -v with --tlsv1.2 or --tlsv1.3 to force a specific TLS version and test compatibility.
For API testing workflows, consider saving frequently used curl commands as shell scripts or aliases. A command like curl -s -H "Authorization: Bearer $API_TOKEN" -H "Content-Type: application/json" https://api.example.com/v1/ is tedious to type repeatedly. Saving it as a function or alias with the base URL and common headers means you only need to append the specific endpoint and body for each test. Many developers maintain a collection of curl commands in a requests.sh file in their project, which also serves as living documentation of the API.
Frequently Asked Questions
How do I send a file as the request body?
Use the @ prefix with -d to read the body from a file: curl -X POST -d @payload.json -H "Content-Type: application/json" https://api.example.com/upload. For multipart file upload, use -F "[email protected]".
What is the difference between -d and -F?
-d sends the body as a single blob (usually application/x-www-form-urlencoded or application/json). -F sends multipart/form-data, which is designed for file uploads and mixed form fields. Use -F when you need to upload files alongside form data.
Should I use -k / --insecure to skip TLS verification?
Only in development environments with self-signed certificates. Never use -k in production scripts or when sending credentials, as it disables certificate verification and opens the connection to man-in-the-middle attacks.
How do I see the response headers along with the body?
Use -i (include) to print response headers before the body, or -v (verbose) to see both request and response headers along with the TLS handshake details. For just the headers without the body, use -I (HEAD request) or -o /dev/null -v to discard the body but show verbose output.
Can curl follow redirects automatically?
Yes. Use -L (or --location) to follow 3xx redirects. By default, curl stops at the first redirect and shows the redirect response. With -L, it follows the chain until it reaches a final response. You can limit the number of redirects with --max-redirs 5.
How do I handle cookies in curl?
Use -b to send cookies and -c to save cookies received from the server. For example, curl -c cookies.txt https://example.com/login -d "user=alice" saves the login cookies, and curl -b cookies.txt https://example.com/dashboard sends them back. This is useful for testing authentication flows that rely on session cookies.
Related Tools
- HTTP Header Formatter - Format headers for use in curl commands
- HTTP Status Code Lookup - Look up status codes returned by curl requests
- CORS Header Explainer - Understand CORS headers when testing cross-origin APIs
- Query String Parser/Builder - Build query strings to append to curl request URLs
- User-Agent Parser - Parse User-Agent strings to set custom values in curl requests