Skip to content

Instantly share code, notes, and snippets.

@techniq
Last active July 13, 2019 01:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techniq/2fbf0ed3e85429a80b01 to your computer and use it in GitHub Desktop.
Save techniq/2fbf0ed3e85429a80b01 to your computer and use it in GitHub Desktop.
curl reference

See response headers

curl -i localhost/api/foo

See request and response headers

curl -v localhost/api/foo

POST with string data

Unix:

curl -X POST -d '"foo"' localhost/api/foo

Windows:

curl -X POST -d "\"foo\"" localhost/api/foo

POST with JSON data

Unix:

curl -X POST -H "Content-Type: application/json" -d '{"foo": "bar"}' localhost/api/foo

Windows:

curl -X POST -H "Content-Type: application/json" -d "{\"foo\": \"bar\"}" localhost/api/foo

Pass Windows credentials as part of request

curl --ntlm -u : example.com

Syntax highlight JSON using jq

curl -s localhost/api/foo | jq .

Count number of returned objects using jq

curl -s localhost/api/foo | jq length

Return partial JSON properties using jq

curl -s localhost/api/foo | jq '.[] | { name: .author.name }'

or shorthand for top-level properties

curl -s localhost/api/foo | jq '.[] | { name }'

Collapse JSON objects to single line

curl -s localhost/api/foo | jq -c '.[] | { name }'

List Keys

curl -s localhost/api/foo | jq '.[0] | keys'

Return response size

curl -s http://www.whatsmyip.org/http-compression-test/ -w '%{size_download}' -o /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment