curl and jq 8 cheatsheet

curl and jq 8: Making requests

9 common curl and jq 8 tasks.

Make a GET request

Fetch a URL and print the response body.

curl https://api.example.com/users

Hide the progress meter

Suppress progress output but still show errors, which suits scripts.

curl -sS https://api.example.com/users

Fetch only the headers

Send a HEAD request and print the response headers.

curl -I https://example.com

Follow redirects

Follow Location headers until the final response.

curl -L https://example.com

POST JSON

Send a JSON body with the correct content type.

curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Ada"}'

POST a JSON file

Send the contents of a file as the request body.

curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d @user.json

Use other HTTP methods

Choose the method with -X, here DELETE.

curl -X DELETE https://api.example.com/users/42

Submit a form

Send URL-encoded form fields.

curl -d "name=Ada&role=admin" https://example.com/form

URL-encode a value

Send a value that needs encoding, as a query string for a GET request.

curl -G https://example.com/search --data-urlencode "q=hello world"

Was this page helpful?