cURL: send requests from the command line
cURL is a command-line tool and library for transferring data through URLs. It is useful for testing APIs, downloading files, and checking server responses.
What you will learn
- How to make a basic HTTP request
- What GET, POST, headers, and a body do
- Why server-side validation is required even when a form validates input
Make a GET request
curl https://example.com/api/taskscURL prints the response body. Add -i when you also want to inspect response headers, or -I to request headers only.
Send a POST body
curl -X POST https://example.com/form-submit \
-H "Content-Type: application/x-www-form-urlencoded" \
--data "age=30&name=Yugien"-X selects a method, -H adds a header, and --data sends the request body. Use the exact content type and format expected by the API.
Client checks are not security
A browser form may say that an age must be between 0 and 120, but another client can send age=9999. Validate type, range, permissions, and business rules on the server before saving or acting on data.
Common mistakes
- Do not paste passwords, API keys, or personal data into a shared terminal or shell history.
- Do not follow redirects or disable TLS verification casually; understand the target first.
- Check the HTTP status and response before assuming a request succeeded.
- Use a test endpoint and test data before sending a destructive request.