homecourse
 
   

cURL basics

Published August 11, 2023Last updated December 16, 20242 min read

cURL is a command line tool for interacting with servers, it can be used in bash scripts to automate some workflows. This post covers primary usage with examples.

  • Send an HTTP GET request to the server
curl ipv4.icanhazip.com
  • Get only the response headers
curl -I ipv4.icanhazip.com
  • Send POST requests with the request body and headers
curl -X POST https://api.gumroad.com/v2/licenses/verify \
-d "product_id=product-id" \
-d "license_key=license-key"
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "What is cURL?"}]
}'
  • Use the i option to include the headers in the response
curl -i -X POST https://api.gumroad.com/v2/licenses/verify \
-d "product_id=product-id" \
-d "license_key=license-key"
  • Use the s option to hide all the logs during the request
curl -s -X POST https://api.gumroad.com/v2/licenses/verify \
-d "product_id=product-id" \
-d "license_key=license-key"
  • Use the v option for verbose logs during the request
curl -v -X POST https://api.gumroad.com/v2/licenses/verify \
-d "product_id=product-id" \
-d "license_key=license-key"
  • Retrieve bash script and run it locally
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
  • Trigger specific endpoint inside Kubernetes cronjob
# ...
containers:
- name: cleanup
# ...
command:
- /bin/sh
- -ec
- 'curl "https://some-service.com/cleanup"'

Course

Build your SaaS in 2 weeks - Start Now