cURL (Client URL), komut satırından HTTP istekleri göndermenizi sağlayan güçlü bir araçtır. API test etme, web hizmetleriyle etkileşim kurma ve otomasyon senaryolarında vazgeçilmez bir yardımcıdır. Neredeyse tüm işletim sistemlerinde önceden yüklü olarak gelir ve 25'ten fazla protokolü destekler.
Temel Kullanım
En basit haliyle cURL, bir URL'ye GET isteği gönderir ve yanıtı terminale yazdırır:
# Basit GET isteği
curl https://api.example.com/users
# Yanıt başlıklarını da göster
curl -i https://api.example.com/users
# Yalnızca yanıt başlıklarını göster
curl -I https://api.example.com/users
# Detaylı çıktı (verbose)
curl -v https://api.example.com/users
HTTP Metotları
GET İsteği
# Basit GET
curl https://api.example.com/users
# Sorgu parametreleriyle
curl "https://api.example.com/users?page=2&limit=10"
# URL kodlama ile
curl -G --data-urlencode "q=türkçe arama" https://api.example.com/search
POST İsteği
# JSON verisi gönderme
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"ad": "Fatih", "email": "[email protected]"}'
# Form verisi gönderme
curl -X POST https://api.example.com/login -d "username=fatih&password=12345"
# Dosyadan JSON verisi okuma
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d @veri.json
PUT ve PATCH İstekleri
# PUT: Kaynağı tamamen güncelle
curl -X PUT https://api.example.com/users/1 -H "Content-Type: application/json" -d '{"ad": "Fatih", "soyad": "Uzuner"}'
# PATCH: Kısmi güncelleme
curl -X PATCH https://api.example.com/users/1 -H "Content-Type: application/json" -d '{"email": "[email protected]"}'
DELETE İsteği
curl -X DELETE https://api.example.com/users/1 -H "Authorization: Bearer TOKEN"
Başlıklar (Headers)
# Özel başlık ekleme
curl -H "Authorization: Bearer eyJhbGciOi..." -H "Accept: application/json" -H "X-Custom-Header: deger" https://api.example.com/profile
Kimlik Doğrulama
# Temel kimlik doğrulama (Basic Auth)
curl -u kullanici:sifre https://api.example.com/secure
# Bearer Token
curl -H "Authorization: Bearer eyJhbGciOi..." https://api.example.com/profile
# API Key
curl -H "X-API-Key: abc123" https://api.example.com/data
Cookie Yönetimi
# Cookie gönderme
curl -b "session=abc123; lang=tr" https://api.example.com/dashboard
# Cookie'leri dosyaya kaydetme
curl -c cookies.txt https://api.example.com/login -d "user=fatih"
# Kaydedilen cookie'leri kullanma
curl -b cookies.txt https://api.example.com/dashboard
Dosya Yükleme
# Tek dosya yükleme
curl -X POST https://api.example.com/upload -F "[email protected]"
# Birden fazla dosya ve ek veri
curl -X POST https://api.example.com/upload -F "[email protected]" -F "[email protected]" -F "aciklama=Proje dosyaları"
Dosya İndirme
# Dosyayı belirtilen isimle kaydet
curl -o indirilecek.zip https://example.com/dosya.zip
# Sunucudaki ismiyle kaydet
curl -O https://example.com/dosya.zip
# İndirme ilerlemesini göster
curl -# -O https://example.com/buyuk-dosya.zip
Sık Kullanılan Bayraklar
-v/--verbose— Detaylı isteği ve yanıt bilgisini gösterir-s/--silent— İlerleme çubuğunu ve hata mesajlarını gizler-L/--location— Yönlendirmeleri takip eder (301, 302)-k/--insecure— SSL sertifikası doğrulamasını atlar (yalnızca test için!)-o— Çıktıyı dosyaya yazar-w— Özel çıktı formatı (yanıt süresi ölçümü vb.)--connect-timeout— Bağlantı zaman aşımı süresi--max-time— Toplam istek zaman aşımı süresi
Yanıt Süresi Ölçme
curl -o /dev/null -s -w "DNS: %{time_namelookup}s
Bağlantı: %{time_connect}s
TTFB: %{time_starttransfer}s
Toplam: %{time_total}s
HTTP Kodu: %{http_code}
" https://sitescripti.com
jq ile JSON Çıktıyı Biçimlendirme
# JSON yanıtını güzelce biçimlendir
curl -s https://api.example.com/users | jq .
# Belirli bir alanı çek
curl -s https://api.example.com/users | jq '.[0].ad'
cURL komutlarını görsel bir arayüzle oluşturmak mı istiyorsunuz? SiteScripti'nin cURL Builder aracıyla metot, başlıklar, kimlik doğrulama ve gövde ayarlarını kolayca yapılandırıp komutu kopyalayabilirsiniz.
Bu konuyla ilgili araçlarımızı da deneyin: cURL Builder, JSON Formatter, Regex Test Aracı