Cheatsheet: curl

Basic operations

Send a GET request to a URL

curl "https://testapi.devtoolsdaily.com/users?limit=5"

Send a POST request with data

curl --data "firstName=John" "https://testapi.devtoolsdaily.com/users/1"

Send a POST request with JSON data

curl -H "Content-Type: application/json" -X POST -d '{"firstName":"John"}'  "https://testapi.devtoolsdaily.com/users/1"

Send a PUT request with data:

curl -X PUT --data "firstName=John" "https://testapi.devtoolsdaily.com/users/1

Send a DELETE request:

curl -X DELETE "https://testapi.devtoolsdaily.com/users/1"

Send a request with a custom header

curl -H "appKey: asdf123123" "https://testapi.devtoolsdaily.com/users/1"

Send a request with Basic Authentication

curl -u username:password "https://testapi.devtoolsdaily.com/users/1"

Send a request and save the response to a file

curl "https://testapi.devtoolsdaily.com/users?limit=5" -o filename.txt

Send a request and follow redirects

curl -L https://testapi.devtoolsdaily.com

Send a request and display the response headers

curl -i https://testapi.devtoolsdaily.com