Introduction to curl Module #42 Flashcards

1
Q

What’s the command for a basic cURL lookup?

A

curl https://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How would you reveal the response headers that are hidden by default?

A

Add in the -i flag.

curl -i https://flaviocopes.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What if you wanted to return ONLY the response headers?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you change the request so that a POST is perform rather than the default GET?

A

curl -X POST https://flaviocopes.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What if you wanted to use POST to pass a bit of data over to the API?

A

curl -d “option=value&something=anothervalue”

-X POST https://flaviocopes.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Instead of a small string, what if you wanted to pass abit of JSON from the command line using CURL?

A

curl -d ‘{“option”: “value”, “something”: “anothervalue”}’ -H “Content-Type: application/json” -X POST https://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Typing JSON in the terminal is highly impractical. Why not send it in a file? How to do that?

A

curl -d “@my-file.json” -X POST https://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you change from an HTTP request to a PUT request?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you follow a redirect using curl?

A

curl -L http://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Sometimes it’s handy to store the request response to a file. How to do that?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What if the resource requires basic HTTP authentication?

A

curl -u user:pass https://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you change the User Agent when making a request?

A

curl –user-agent “my-user-agent” https://flaviocopes.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you capture a detailed report of the request?

A

Use the –verbose option to make curl output all the details of the request, and the response:

curl –verbose -I https://flaviocopes.com/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly