πŸ‘ˆ

πŸ”Ή What is curl?

curl stands for Client URL.

It is a command-line tool used to send requests to URLs and get responses from servers.

πŸ‘‰ In simple words:

curl is used to talk to servers from the terminal

You can:

  • Call APIs (REST APIs)
  • Download files
  • Upload files
  • Send GET, POST, PUT, DELETE requests
  • Send headers, tokens, cookies
  • Test backend APIs (Django, Spring Boot, Node, etc.)

πŸ”Ή Where is curl used?

  • Backend developers (API testing)
  • DevOps (health checks, automation)
  • Cloud engineers (AWS, servers)
  • CI/CD pipelines
  • Debugging production APIs

πŸ”Ή Is curl installed by default?

OSStatus
Linuxβœ… Yes
macOSβœ… Yes
Windows 10+βœ… Yes (new versions)

Check:

curl --version

πŸ”Ή Basic curl syntax

curl [options] URL

Example:

curl https://example.com

πŸ‘‰ This sends a GET request to the server.


πŸ”Ή HTTP Methods in curl

MethodPurpose
GETFetch data
POSTCreate data
PUTUpdate full data
PATCHUpdate partial data
DELETERemove data

πŸ”Ή GET Request (Most common)

curl https://api.example.com/users

With query params:

curl "https://api.example.com/users?id=10"

πŸ”Ή Show full response (headers + body)

curl -i https://example.com

πŸ”Ή Show only headers

curl -I https://example.com

πŸ”Ή Pretty print JSON response

curl https://api.example.com/users | jq

(jq is a JSON formatter tool)


πŸ”Ή POST Request (Send data)

Send JSON data

curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Dev","age":22}'

Explanation:

  • -X POST β†’ HTTP method
  • -H β†’ Header
  • -d β†’ Data (body)

πŸ”Ή PUT Request (Update)

curl -X PUT https://api.example.com/users/1 \
-H "Content-Type: application/json" \
-d '{"name":"Dev","age":23}'

πŸ”Ή PATCH Request (Partial update)

curl -X PATCH https://api.example.com/users/1 \
-H "Content-Type: application/json" \
-d '{"age":24}'

πŸ”Ή DELETE Request

curl -X DELETE https://api.example.com/users/1

πŸ”Ή Sending Headers (Auth tokens, etc.)

curl https://api.example.com/profile \
-H "Authorization: Bearer YOUR_TOKEN"

Multiple headers:

curl https://api.example.com \
-H "Accept: application/json" \
-H "User-Agent: curl-test"

πŸ”Ή Authentication with curl

Basic Auth

curl -u username:password https://api.example.com

Bearer Token

curl -H "Authorization: Bearer TOKEN" https://api.example.com

πŸ”Ή Upload file using curl

curl -X POST https://api.example.com/upload \
-F "file=@image.png"

πŸ”Ή Download file using curl

curl -O https://example.com/file.zip

Rename file:

curl -o myfile.zip https://example.com/file.zip

πŸ”Ή Follow redirects

curl -L https://short.url

πŸ”Ή Save response to file

curl https://api.example.com/data -o data.json

πŸ”Ή Timeout in curl

curl --max-time 10 https://example.com

πŸ”Ή Silent mode (no progress)

curl -s https://example.com

πŸ”Ή Verbose / Debug mode (VERY IMPORTANT)

curl -v https://example.com

πŸ‘‰ Shows:

  • DNS lookup
  • TLS handshake
  • Request headers
  • Response headers

πŸ”Ή Common curl options (Must know)

OptionMeaning
-XHTTP method
-HHeader
-dData
-iInclude headers
-IOnly headers
-vVerbose
-sSilent
-oOutput file
-OSave with original name
-LFollow redirects
-uAuthentication

πŸ”Ή curl vs Postman

curlPostman
CLI basedGUI based
LightweightHeavy
Used in serversUsed in local testing
AutomatableManual

πŸ‘‰ In real projects, both are used


πŸ”Ή curl in Backend Development (Your case)

Since you work with Django APIs & Angular, curl is useful for:

  • Testing API endpoints without frontend
  • Checking auth headers
  • Debugging POST/GET issues
  • Server health checks on EC2

Example for Django:

curl http://127.0.0.1:8000/api/expenses/

πŸ”Ή Common curl mistakes ❌

  1. Forgetting quotes around JSON
  2. Missing Content-Type
  3. Wrong HTTP method
  4. Sending GET with -d
  5. Forgetting -L for redirects

πŸ”Ή Interview-ready answer

Q: What is curl?

curl is a command-line tool used to transfer data between a client and a server using protocols like HTTP, HTTPS, FTP, etc. It is commonly used for testing APIs, downloading/uploading files, and debugging network requests.


πŸ”Ή When should you use curl?

  • When you don’t have frontend
  • When debugging APIs on server
  • When automating API calls
  • When Postman is not available