Fetch HTTP
Make HTTP requests using curl for APIs and web services.
Process
- Identify request type - GET, POST, PUT, DELETE, etc.
- Prepare headers - Content-Type, Authorization, Accept
- Format request body - JSON, form data, or other payload
- Execute request - Use curl with appropriate flags
- Check status code - Verify request succeeded
- Parse response - Use jq for JSON, or other tools for different formats
Examples
# GET
curl -sS "https://example.com"
GET with headers
curl -sS -H "Accept: application/json" "https://api.example.com/v1/items"
POST JSON
curl -sS -X POST "https://api.example.com/v1/items" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"name":"example","enabled":true}'
Save response and check status
curl -sS -o /tmp/resp.json -w "%{http_code}\n" "https://api.example.com/v1/items"
cat /tmp/resp.json
Tips
- Add
-Lto follow redirects. - Use
jqto filter JSON responses. - Keep secrets in environment variables, not inline.