curl Basics

Everything you need to know to get started with curl.

What is curl?

curl is a command-line tool for transferring data using various protocols, most commonly HTTP and HTTPS.

curl https://example.com

GET Requests

The default method. Simply provide a URL to fetch its content.

curl https://api.example.com/users

POST Requests

Use -X POST to send data to a server.

curl -X POST -d "name=John" https://api.example.com/users

Adding Headers

Use -H to add custom headers to your request.

curl -H "Content-Type: application/json" https://api.example.com

Saving Output

Use -o to save the response to a file.

curl -o output.html https://example.com

Following Redirects

Use -L to automatically follow redirects.

curl -L https://example.com/redirect