cURL by Example: Basic Request
Perform a simple GET request. This sample shows the default behavior.
Code
# Simple GET request
curl https://api.example.com/users
# Verbose mode (shows headers and handshake)
curl -v https://api.example.com/users
# Save output to a file
curl -o users.json https://api.example.com/users
# Follow redirects (if any)
curl -L https://example.comExplanation
The most basic usage of cURL is to make a GET request to a specified URL. By default, cURL outputs the response body to standard output (the terminal). This is useful for quickly inspecting the content of a page or API endpoint. cURL is designed to work in a scriptable way without user interaction, making it perfect for automation and testing workflows.
The -v (or --verbose) flag activates verbose mode, providing a detailed output of the entire HTTP transaction. This is an essential tool for developers and system administrators when troubleshooting connectivity issues or when a cURL command doesn't behave as expected. Verbose mode reveals connection details including the IP address and port being accessed, all request headers sent by cURL (like User-Agent and Accept), request body content if present, TLS/SSL handshake information for HTTPS requests (including certificate verification, CA certificates used, and cipher selection), all response headers from the server, and details about response body processing. Informational texts in verbose output are prefixed with an asterisk (*), distinguishing them from actual request/response data. For even more granular detail, the --trace-ascii option can provide all data sent and received in unencrypted form.
If you want to save the response to a file instead of printing it to the screen, use the -o (lowercase o) flag followed by the filename. The -L flag tells cURL to follow HTTP redirects (3xx status codes), which it does not do by default. Without this flag, cURL simply displays the redirect response itself rather than following the Location header to the final destination.
Code Breakdown
curl [URL] performs a GET request by default.-o filename writes the output to a file.
