In today's interconnected world, API testing and HTTP requests have become essential skills for developers. One of the most powerful command-line tools for these tasks is curl. Whether you're debugging an API, downloading files, or testing your web application, curl offers versatility that few other tools can match.
This guide covers the top 10 most commonly used curl commands that every developer should know, with practical examples and explanations to help you master this essential tool.
The simplest and most common use of curl is making a GET request to fetch data from a URL:
curl https://example.comThis command retrieves the HTML content of the specified website. By default, curl outputs the response body to your terminal.
Key options to enhance basic GET requests:
-i or --include: Includes HTTP headers in the output
-s or --silent: Makes curl silent, hiding the progress meter and error messages
Example with headers:
curl -i https://api.github.com
Curl excels at downloading files from the internet with its simple yet powerful syntax:
curl -O https://example.com/file.zipThe -O option saves the file with its original filename in your current directory. For more control over the download:
curl -o custom_name.zip https://example.com/file.zipWhen dealing with interrupted downloads, curl can resume where it left off:
curl -C - -O https://example.com/large-file.isoThe -C - option tells curl to automatically figure out where to resume the download from.
Sending data to web servers is another common curl task. To make a POST request with form data:
curl -X POST -d "name=John&email=john@example.com" https://example.com/submitFor JSON data, which is common in modern APIs:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@example.com"}' \
https://api.example.com/usersJSON data can also be sent from a file, which is useful for complex payloads:
curl -X POST -H "Content-Type: application/json" -d @data.json https://api.example.com/users
Many APIs require authentication. Curl supports various authentication methods, with basic auth being the simplest:
curl -u username:password https://api.example.com/secureFor bearer token authentication, commonly used in OAuth 2.0 flows:
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.example.com/resourcesThis method is widely used when working with modern APIs from services like GitHub, Twitter, or your own secured endpoints.
Setting HTTP headers is essential when working with APIs:
curl -H "User-Agent: MyApp/1.0" https://api.example.comMultiple headers can be specified for more complex requests:
curl -H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer token123" \
https://api.example.com/dataHeaders help you control how your request is processed and what format responses should be in.
Many websites use redirects. By default, curl doesn't follow them, but you can enable this behavior:
curl -L https://shortened-url.comThe -L option makes curl follow redirects automatically. You can also limit the number of redirects:
curl -L --max-redirs 3 https://example.comThis prevents curl from following endless redirect loops, which can happen with misconfigured websites.
When troubleshooting API calls or understanding how a website responds, verbose mode is invaluable:
curl -v https://api.example.comFor even more detailed information, especially about SSL/TLS handshakes:
curl --trace output.txt https://api.example.comThe verbose output shows:
Request headers sent by curl
Response headers received from the server
SSL/TLS negotiation details
Data transfers
This information is crucial when debugging connection issues or API problems.
When working with potentially slow servers, setting timeouts prevents your script from hanging indefinitely:
curl --connect-timeout 10 https://slow-server.comYou can also set a maximum time for the entire operation:
curl --max-time 30 https://slow-server.com/large-fileSetting appropriate timeouts is essential in automated scripts to handle network issues gracefully.
For testing or accessing region-restricted content, proxy support comes in handy:
curl -x http://proxy-server:8080 https://example.comFor SOCKS proxies, which are often used with SSH tunnels:
curl --socks5 localhost:1080 https://example.comProxies can help you test your applications from different geographic locations or bypass network restrictions.
Instead of displaying the response in the terminal, you might want to save it to a file:
curl -o response.json https://api.example.com/dataFor more complex scenarios, you can split headers and body into separate files:
curl -D headers.txt -o body.html https://example.comThis approach is useful when you need to analyze responses thoroughly or process them with other tools.
Mastering these ten curl commands will significantly enhance your development workflow. While curl offers hundreds of options, these core commands cover most day-to-day scenarios developers encounter.
For those looking to dive deeper, the official curl documentation is comprehensive and well-maintained. You might also consider exploring tools built on top of curl, such as Postman or Insomnia, which offer graphical interfaces for API testing while leveraging curl's powerful capabilities underneath.
What's your favorite curl command or trick? Share in the comments below!
Qodex.ai simplifies and accelerates the API testing process by leveraging AI-powered tools and automation. Here's why it stands out:
Achieve 100% API testing automation without writing a single line of code. Qodex.ai’s cutting-edge AI reduces manual effort, delivering unmatched efficiency and precision.
Effortlessly import API collections from Postman, Swagger, or application logs and begin testing in minutes. No steep learning curves or technical expertise required.
Whether you’re using AI-assisted test generation or creating test cases manually, Qodex.ai adapts to your needs. Build robust scenarios tailored to your project requirements.
Gain instant insights into API health, test success rates, and performance metrics. Our integrated dashboards ensure you’re always in control, identifying and addressing issues early.
Designed for teams of all sizes, Qodex.ai offers test plans, suites, and documentation that foster seamless collaboration. Perfect for startups, enterprises, and microservices architecture.
Save time and resources by eliminating manual testing overhead. With Qodex.ai’s automation, you can focus on innovation while cutting operational costs.
Easily integrate Qodex.ai into your CI/CD pipelines to ensure consistent, automated testing throughout your development lifecycle.
You can use the following regex pattern to validate an email address: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Go Regex Tester is a specialized tool for developers to test and debug regular expressions in the Go programming environment. It offers real-time evaluation of regex patterns, aiding in efficient pattern development and troubleshooting
Auto-discover every endpoint, generate functional & security tests (OWASP Top 10), auto-heal as code changes, and run in CI/CD - no code needed.


