Mastering curl: The Swiss Army Knife of the Command Line



This content originally appeared on DEV Community and was authored by Khaled Md Saifullah

If you have ever tested endpoints worked with APIs or uploaded files it is likely that someone advised you to “just use curl.” However, what is curl exactly and why is it a tool that developers have on hand? Let’s dissect it.

What is curl?

“curl” is an acronym for “client URL.” To move data to and from a server use this command-line utility tool. It’s like the browser on your terminal, but with a lot more control.

What we can do with curl?

  • Fetch data from APIs
  • Send POST requests
  • Upload files and images
  • Test authentication and headers
  • Work with different protocols (HTTP, HTTPS, FTP etc.)

In short: if you want to talk to a server, curl is your friend.

Why Developers Love curl?

  • Cross-platform: Works on Linux, macOS and Windows
  • Protocol-rich: Supports HTTP, HTTPS, FTP, SFTP, SCP and more
  • Powerful for testing: Great for debugging APIs without writing code
  • Scriptable: Perfect for automation and shell scripts

Basic Usage of curl

  1. Make a GET request
curl http://localhost:8000

This fetches data from server.

  1. Make a POST request
curl -X POST http://localhost:8000/post \
  -d "name=John&age=25"

-X POST: sets the request method to POST
-d: sends form data

  1. Send JSON data
curl -X POST http://localhost:8000/post \
  -H "Content-Type: application/json" \
  -d '{"username":"john doe","password":"secret"}'
  1. Add authentication
curl -u username:password http://localhost:8000/protected

or with a token

curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8000/api

Uploading a File with curl

Upload a single photo

curl -X POST http://localhost:8000/upload \
  -F "file=@myphoto.jpg"

Upload with extra data

curl -X POST http://localhost:8000/upload \
  -F "file=@myphoto.jpg" \
  -F "userId=12345" \
  -F "description=Profile picture"

Upload with authentication

curl -X POST http://localhost:8000/upload \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "file=@myphoto.jpg"

Downloading Files with curl

Want to grab a file from the internet?

curl -O http://localhost:8000/file.zip

-o: saves the file with the same name as on the server.

Or specify a custom name

curl -o myfile.zip http://localhost:8000/file.zip

Debugging with curl

Sometimes you want to see what’s really happening under the hood

curl -v http://localhost:8000
curl -i http://localhost:8000

-v: verbose mode (shows request/response details)
-i: includes response headers in the output

Conclusion

Curl is a developer’s Swiss Army knife not just a tool. It streamlines operations and saves time for anything from file uploads and downloads to rapid API testing.

Use curl the next time you are automating, debugging or building. You will question how you managed without it once you are at ease with it.


This content originally appeared on DEV Community and was authored by Khaled Md Saifullah