Curl Exercises

Questions & Answers

What is the purpose of curl?

CLICK FOR ANSWER

To craft HTTP(s) requests and receive HTTP(s) responses allowing you to transfer data from or to a server.

How do you make a GET request to www.google.com?

CLICK FOR ANSWER
curl www.google.com

How do you change the HTTP request method using curl?

CLICK FOR ANSWER

With the -X option.

Get

curl -X GET [URL]

Post

curl -X POST [URL]

Put

curl -X PUT [URL]

Patch

curl -X PATCH [URL]

Delete

curl -X DELETE [URL]

How do you include a request header with curl?

CLICK FOR ANSWER

With the -H option.

Adding a Content-Type: application/json header

curl -X POST [URL] -H 'Content-Type:application/json'

How do you include a request body with curl?

CLICK FOR ANSWER

With the -d option.

Adding a JSON request body

curl -X POST [URL] -d '{"animalType": "dog", "name": "Bernie", "age": 6}'