How to Make an HTTP Request with cURL
cURL is a command-line tool for making HTTP requests. It's available on most systems (Linux, macOS, Windows) and is widely used for API testing, scripting, and debugging. No installation is needed on most Unix-like systems—it's often pre-installed.
GET request example
Making a GET request to fetch data with custom headers:
curl -X GET "https://api.example.com/users" \
-H "Accept: application/json" \
-H "Authorization: Bearer YOUR_TOKEN"POST request example
Making a POST request to send JSON data:
curl -X POST "https://api.example.com/users" \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "john@example.com"}'PUT request example
Replacing a resource with PUT:
curl -X PUT "https://api.example.com/users/123" \
-H "Content-Type: application/json" \
-d '{"name": "John Updated", "email": "john.new@example.com"}'PATCH request example
Partially updating a resource with PATCH:
curl -X PATCH "https://api.example.com/users/123" \
-H "Content-Type: application/json" \
-d '{"email": "john.updated@example.com"}'DELETE request example
Deleting a resource:
curl -X DELETE "https://api.example.com/users/123" \
-H "Authorization: Bearer YOUR_TOKEN"Error handling
Check the HTTP status code with -w '%{http_code}' or inspect the response. Use -s for silent mode (no progress) and -S to show errors. For production scripts, always verify the status before assuming success.
# Get status code and body
HTTP_CODE=$(curl -s -o /tmp/response.json -w "%{http_code}" "https://api.example.com/users")
if [ "$HTTP_CODE" -eq 200 ]; then
cat /tmp/response.json
else
echo "Error: HTTP $HTTP_CODE"
fiTry it in Send Web Request
You can run these cURL commands directly in Send Web Request. Paste any curl command and we'll parse it—or build your request visually and export it as curl.
Open Send Web RequestOther libraries you can try
- Python:
Requests— simple and popular HTTP library,HTTPX— async-capable HTTP client - JavaScript:
Axios— promise-based HTTP client,node-fetch— Fetch API for Node.js - Ruby:
HTTParty— simple HTTP client,Faraday— flexible HTTP library,RestClient— lightweight REST client - Java:
OkHttp— efficient HTTP client,Apache HttpClient— feature-rich library - C#:
RestSharp— simple REST client,Flurl— fluent HTTP library - Go (Golang):
resty— simple HTTP client,grequests— goroutine-based requests - PHP:
Guzzle— popular PHP HTTP client,Symfony HttpClient— component-based HTTP client