cURL Essential Commands Cheatsheet
Goal
Provide a quick reference for commonly used cURL commands.
GET Request
curl localhost:8080
POST Form Data
Default content type is application/x-www-form-urlencoded:
curl -X POST http://localhost:8080/data -d "param1=value1¶m2=value2"
curl -X POST http://localhost:3000/data -d "@data.txt"
POST JSON
curl -X POST http://localhost:3000/data -H "Content-Type: application/json" -d '{\"key1\":\"value1\", \"key2\":\"value2\"}'
curl -X POST http://localhost:3000/data -H "Content-Type: application/json" -d "@data.json"
In PowerShell, escape double quotes with \.
Skip Certificate Validation
curl -k https://localhost:8080
Bearer Token Authentication
curl https://bustroker.com/api/resource -H 'Accept: application/json' -H "Authorization: Bearer <TOKEN>"
Add Newline After Output
curl localhost:8080 ;echo
Format JSON Response (Linux)
Using json_pp:
curl localhost:8080 | json_pp
Using jq:
curl localhost:8080 | jq "."
Extract JSON Properties (Linux)
The -r flag outputs raw values without surrounding quotes:
curl localhost:8080 | jq -r ".some.property.in_Json.tree"