π
πΉ 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?
| OS | Status |
|---|---|
| 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
| Method | Purpose |
|---|---|
| GET | Fetch data |
| POST | Create data |
| PUT | Update full data |
| PATCH | Update partial data |
| DELETE | Remove 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)
| Option | Meaning |
|---|---|
-X | HTTP method |
-H | Header |
-d | Data |
-i | Include headers |
-I | Only headers |
-v | Verbose |
-s | Silent |
-o | Output file |
-O | Save with original name |
-L | Follow redirects |
-u | Authentication |
πΉ curl vs Postman
| curl | Postman |
|---|---|
| CLI based | GUI based |
| Lightweight | Heavy |
| Used in servers | Used in local testing |
| Automatable | Manual |
π 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 β
- Forgetting quotes around JSON
- Missing
Content-Type - Wrong HTTP method
- Sending GET with
-d - Forgetting
-Lfor 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