DEV Community

Željko Šević
Željko Šević

Posted on • Originally published at sevic.dev on

cURL basics

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
Enter fullscreen mode Exit fullscreen mode
  • Get only the response headers
curl -I ipv4.icanhazip.com
Enter fullscreen mode Exit fullscreen mode
  • 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?"}]
  }'
Enter fullscreen mode Exit fullscreen mode
  • 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"
Enter fullscreen mode Exit fullscreen mode
  • 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"
Enter fullscreen mode Exit fullscreen mode
  • 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"
Enter fullscreen mode Exit fullscreen mode
  • Retrieve bash script and run it locally
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • Trigger specific endpoint inside Kubernetes cronjob
# ...
containers:
  - name: cleanup
    # ...
    command:
      - /bin/sh
      - -ec
      - 'curl "https://some-service.com/cleanup"'
Enter fullscreen mode Exit fullscreen mode

Course

Build your SaaS in 2 weeks - Start Now

Retry later

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more