Fetch HTTP

Make HTTP requests using curl for APIs and web services.

Process

  1. Identify request type - GET, POST, PUT, DELETE, etc.
  2. Prepare headers - Content-Type, Authorization, Accept
  3. Format request body - JSON, form data, or other payload
  4. Execute request - Use curl with appropriate flags
  5. Check status code - Verify request succeeded
  6. 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