Introduction to curl Module #42 Flashcards
What’s the command for a basic cURL lookup?
curl https://flaviocopes.com/
How would you reveal the response headers that are hidden by default?
Add in the -i flag.
curl -i https://flaviocopes.com
What if you wanted to return ONLY the response headers?
curl -I https://flaviocopes.com the return looks something like this if successful:
HTTP/2 200
cache-control: public, max-age=0, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
date: Thu, 13 May 2021 04:15:58 GMT
etag: “980bc08d18e291b88852574e16a19815-ssl”
strict-transport-security: max-age=31536000
age: 1
x-nf-request-id: 01bb9ed8-60c1-4c4b-858b-8e104f923005
server: Netlify
How would you change the request so that a POST is perform rather than the default GET?
curl -X POST https://flaviocopes.com
What if you wanted to use POST to pass a bit of data over to the API?
curl -d “option=value&something=anothervalue”
-X POST https://flaviocopes.com
Instead of a small string, what if you wanted to pass abit of JSON from the command line using CURL?
curl -d ‘{“option”: “value”, “something”: “anothervalue”}’ -H “Content-Type: application/json” -X POST https://flaviocopes.com/
Typing JSON in the terminal is highly impractical. Why not send it in a file? How to do that?
curl -d “@my-file.json” -X POST https://flaviocopes.com/
How would you change from an HTTP request to a PUT request?
The concept is the same as for POST requests, just change the HTTP method using -X PUT
/* Hmm, it might be a good idea to find out what a PUT request is for */
How would you follow a redirect using curl?
curl -L http://flaviocopes.com/
Sometimes it’s handy to store the request response to a file. How to do that?
curl -o file.html https://flaviocopes.com OR You can also just save a file by its name on the server, using the O option:
curl -O https://flaviocopes.com/index.html
What if the resource requires basic HTTP authentication?
curl -u user:pass https://flaviocopes.com/
How would you change the User Agent when making a request?
curl –user-agent “my-user-agent” https://flaviocopes.com
How would you capture a detailed report of the request?
Use the –verbose option to make curl output all the details of the request, and the response:
curl –verbose -I https://flaviocopes.com/