Curl

From wikinotes

Tutorials

curl book https://everything.curl.dev/http/cookies

Debugging

curl -v -X GET https://google.com/blah  # print info as command runs (good to see what part of rest api is slow send, receive, etc)

Downloading Files

curl -#O https://example.com/file         # download, using original filename, and progressbar
curl https://example.com/file -o out.tgz  # download to out.tgz

# download from ftp
curl ftp://myftpsite.com/mp3/mozart_piano_sonata.zip \
  --user myname:mypassword \
  -o mozart_piano_sonata.zip

# list ftp dirs
curl ftp://myftpsite.com/mp3/  --user myname:mypassword

HTTP methods

curl http://127.0.0.1:5984                                    ## test access to database

curl -X GET     http://127.0.0.1:5984/test_database/document  ## get a file

curl -X PUT     http://127.0.0.1:5984/test_database           ## create a database

curl -X DELETE  http://127.0.0.1:5984/test_database           ## delete a database/document

curl -X POST    http://127.0.0.1:5984/test_database/document \ 
                -H 'Content-Type: application/json'          \
                -d @/path/to/file.json                        ## update a file

curl -X GET \
    -H 'Content-Type: application/json' \
    -d '{"user": "me"}' \
     http:/my.domain.com

Headers

# set header
curl -X GET -H 'user: will;pass: abc' 127.0.0.1:/5000/login

# show response headers
curl -X GET \
  -D -          `# show response headers` \
  -o /dev/null  `# redirect response body to dev/null` \
  127.0.0.1:5000/login