cURL usefull commands cheatsheet

Basic GET

curl localhost:8080

Basic POST. application/x-www-form-urlencoded is the default

curl -X POST http://localhost:8080/data -d "param1=value1&param2=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"

Double quotes are escaped with \, required for powershell.

Disable certificate validation

curl -k https://localhost:8080

Add bearer token header

curl -H 'Accept: application/json' -H "Authorization: Bearer <TOKEN>" 

New line after output

curl localhost:8080 ;echo

[Linux] Pretty format json output

curl localhost:8080 | json_pp

also, jq would do it

curl localhost:8080 | jq "."

[Linux] Use jq to extract properties from json response

-r: raw output (i.e., output with no surrounding quotes)

curl localhost:8080 | jq -r ""