A Small yet Extremely Powerful CLI Tool: curl

Getting to know with curl
What is curl?
curl adalah tool berbasis command line interface (CLI) untuk mendapatkan dan mengirim data, termasuk file, menggunakan URL syntax.1 Tool yang “dipersenjatai” oleh libcurl ini gratis dan open source sejak pertama kali dibuat oleh Daniel Stenberg pada tahun 1996 hingga saat ini.2
Link website resmi curl: https://curl.se/
Repository resmi Github:
What is curl used for?
curl digunakan di command line atau di dalam script untuk melakukan transfer data. curl bisa dibilang juga merupakan libcurl di saat yang sama. Oleh karena itu, ia bisa digunakan di mobil, TV, router, printer, peralatan audio, mobile phone, tablet, perangkat medis, STB, game komputer, media player, dan semua aplikasi (software) yang terkait dengan transfer data di internet. curl juga mendukung banyak protokol, seperti HTTP/HTTPS, FTP/SFTP, SMB, SCP, LDAP, IMAP/IMAPS, POP3, TELNET, dan masih banyak lagi.2
Installation
Berikut adalah cara instalasi curl di beberapa sistem operasi linux dan unix:
sudo apt install -y curlsudo pacman -Sy curlsudo dnf install curlsudo zypper install curlsudo pkg install bind-curlNixOS:
Masukkan baris berikut di file konfigurasi (/etc/nixos/configuration.nix):
environment.systemPackages = [ pkgs.curl];Atau jika menggunakan nix-shell:
nix-shell -p curlUsage
These commands are from AI (Anthropic Claude) with “Sonnet 5.5 Medium” model.
Basic Requests
# GET sederhana (output ke terminal)curl https://example.com
# Simpan output ke file dengan nama sendiricurl -o halaman.html https://example.com
# Simpan dengan nama file sesuai di servercurl -O https://example.com/file.zip
# Download beberapa file sekaliguscurl -O https://example.com/a.zip -O https://example.com/b.zip
# Pola URL (globbing)curl -O "https://example.com/img[1-10].jpg"curl -O "https://example.com/{foto,video,doc}.zip"
# Ikuti redirect (301/302)curl -L https://bit.ly/contoh
# Mode senyap (tanpa progress bar), tapi tetap tampilkan errorcurl -sS https://example.com
# Hanya tampilkan header responsecurl -I https://example.com
# Tampilkan header + bodycurl -i https://example.com
# Verbose (lihat seluruh proses request/response, TLS handshake, dsb.)curl -v https://example.comHTTP Method
# POST dengan form data (application/x-www-form-urlencoded)curl -X POST -d "nama=Alex&umur=25" https://httpbin.org/post
# -d otomatis jadi POST, jadi -X POST sebenarnya opsionalcurl -d "nama=Alex" https://httpbin.org/post
# POST JSONcurl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -d '{"nama":"Alex","hobi":["linux","SNA"]}'
# Kirim body dari filecurl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -d @data.json
# Shortcut JSON (curl >= 7.82)curl --json '{"nama":"Alex"}' https://httpbin.org/post
# PUTcurl -X PUT https://api.example.com/users/1 \ -H "Content-Type: application/json" \ -d '{"nama":"Baru"}'
# PATCHcurl -X PATCH https://api.example.com/users/1 \ -H "Content-Type: application/json" \ -d '{"email":"baru@example.com"}'
# DELETEcurl -X DELETE https://api.example.com/users/1
# OPTIONS (cek method yang diizinkan / CORS)curl -X OPTIONS -i https://api.example.com/users
# HEADcurl --head https://example.comHeader, Cookie, and User-Agent
# Custom headercurl -H "Accept: application/json" -H "X-Custom: nilai" https://httpbin.org/headers
# Ganti User-Agentcurl -A "Mozilla/5.0 (X11; Linux x86_64)" https://httpbin.org/user-agent
# Set Referercurl -e "https://google.com" https://example.com
# Kirim cookie manualcurl -b "sesi=abc123; tema=gelap" https://httpbin.org/cookies
# Simpan cookie dari server ke filecurl -c cookies.txt https://example.com/login
# Pakai cookie dari file (simulasi sesi login)curl -b cookies.txt https://example.com/dashboard
# Simpan & pakai sekaliguscurl -b cookies.txt -c cookies.txt https://example.com/halaman
# Hapus header default (misal Accept)curl -H "Accept:" https://example.comAuthentication
# Basic authcurl -u username:password https://httpbin.org/basic-auth/username/password
# Prompt password (tidak muncul di history shell)curl -u username https://example.com/private
# Bearer token (JWT / API token)curl -H "Authorization: Bearer eyJhbGciOi..." https://api.example.com/me
# API key lewat headercurl -H "X-API-Key: kunci_rahasia" https://api.example.com/data
# API key lewat query stringcurl "https://api.example.com/data?api_key=kunci_rahasia"
# Digest authcurl --digest -u user:pass https://example.com/digest
# NTLMcurl --ntlm -u user:pass https://intranet.example.com
# Baca kredensial dari ~/.netrccurl -n https://example.com/private
# Token dari variabel environmentcurl -H "Authorization: Bearer $TOKEN" https://api.example.com/meFile Uploading
# Multipart form upload (seperti form HTML dengan <input type=file>)curl -F "file=@foto.jpg" https://httpbin.org/post
# Dengan field tambahancurl -F "file=@laporan.pdf" -F "judul=Laporan Q3" -F "tag=penting" https://example.com/upload
# Atur content-type & nama filecurl -F "file=@data.bin;type=application/octet-stream;filename=baru.bin" https://example.com/upload
# Upload banyak filecurl -F "files[]=@a.jpg" -F "files[]=@b.jpg" https://example.com/upload
# PUT raw file (misal ke S3 presigned URL)curl -T arsip.tar.gz "https://bucket.s3.amazonaws.com/arsip.tar.gz?X-Amz-..."
# Upload via FTPcurl -T file.txt ftp://ftp.example.com/ --user user:pass
# Upload via SFTPcurl -T file.txt sftp://example.com/home/user/ --user user:passDownload (Advanced)
# Lanjutkan download yang terputuscurl -C - -O https://example.com/besar.iso
# Progress bar sederhanacurl -# -O https://example.com/file.zip
# Batasi kecepatan (misal 500 KB/s)curl --limit-rate 500k -O https://example.com/file.zip
# Download rentang byte tertentucurl -r 0-1023 -o potongan.bin https://example.com/file.bin
# Hanya download kalau file lebih baru dari tanggal tertentucurl -z "2026-01-01" -O https://example.com/file.zip
# Pakai nama dari header Content-Dispositioncurl -OJL https://example.com/download?id=123
# Buat folder otomatis saat -ocurl --create-dirs -o hasil/sub/file.html https://example.com
# Parallel download (curl >= 7.66)curl --parallel --parallel-max 5 -O https://example.com/a.zip -O https://example.com/b.zip -O https://example.com/c.zip
# Download & ekstrak langsung tanpa simpancurl -sL https://example.com/arsip.tar.gz | tar xz
# Cek ukuran file tanpa downloadcurl -sI https://example.com/file.zip | grep -i content-lengthTimeout, Retry, and Error Handling
# Timeout koneksi (detik)curl --connect-timeout 5 https://example.com
# Batas total waktucurl --max-time 30 https://example.com
# Retry otomatis kalau gagalcurl --retry 5 --retry-delay 2 --retry-all-errors https://example.com
# Gagal (exit code != 0) kalau HTTP 4xx/5xxcurl --fail https://example.com/tidak-adacurl -f https://example.com/tidak-ada
# Fail tapi tetap tampilkan body errorcurl --fail-with-body https://api.example.com/error
# Cek exit codecurl -sf https://example.com > /dev/null && echo "OK" || echo "GAGAL"
# Batasi jumlah redirectcurl -L --max-redirs 3 https://example.comHTTPS, TLS, Certificate
# Abaikan verifikasi sertifikat (HANYA untuk testing lokal!)curl -k https://self-signed.local
# Pakai CA certificate sendiricurl --cacert ca.pem https://internal.example.com
# Client certificate (mutual TLS)curl --cert client.pem --key client.key https://mtls.example.com
# Paksa versi TLScurl --tlsv1.2 https://example.comcurl --tls-max 1.2 https://example.com
# Paksa HTTP versi tertentucurl --http1.1 https://example.comcurl --http2 https://example.comcurl --http3 https://example.com
# Lihat detail sertifikatcurl -vI https://example.com 2>&1 | grep -A 10 "Server certificate"
# Override DNS (tes server baru sebelum DNS berubah)curl --resolve example.com:443:203.0.113.10 https://example.com
# Connect ke IP tertentu tapi pakai host headercurl --connect-to example.com:443:203.0.113.10:443 https://example.comProxy
# HTTP proxycurl -x http://proxy.local:8080 https://example.com
# Proxy dengan autentikasicurl -x http://proxy.local:8080 -U user:pass https://example.com
# SOCKS5 proxy (misal Tor)curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
# Lewat proxy environment variableexport https_proxy=http://proxy.local:8080curl https://example.com
# Bypass proxy untuk host tertentucurl --noproxy "localhost,127.0.0.1" https://localhost:3000Performance & Debugging check
# Status code sajacurl -s -o /dev/null -w "%{http_code}\n" https://example.com
# Waktu detailcurl -s -o /dev/null -w "DNS lookup : %{time_namelookup}sTCP connect : %{time_connect}sTLS handshake: %{time_appconnect}sTTFB : %{time_starttransfer}sTotal : %{time_total}sUkuran : %{size_download} bytesKecepatan : %{speed_download} B/s" https://example.com
# Simpan format ke file (curl-format.txt), lalu pakaicurl -w "@curl-format.txt" -o /dev/null -s https://example.com
# URL akhir setelah redirectcurl -Ls -o /dev/null -w "%{url_effective}\n" https://bit.ly/contoh
# IP server yang dihubungicurl -s -o /dev/null -w "%{remote_ip}\n" https://example.com
# Trace lengkap (hex dump)curl --trace-ascii trace.log https://example.com
# Cek apakah server support kompresicurl -sI -H "Accept-Encoding: gzip, br" https://example.com | grep -i content-encoding
# Minta response terkompresi & dekompres otomatiscurl --compressed https://example.com
# Cek header keamanan sebuah situscurl -sI https://example.com | grep -iE "strict-transport|content-security|x-frame|x-content-type"REST API + jq
# Ambil data & rapikan JSONcurl -s https://api.github.com/users/torvalds | jq .
# Ambil field tertentucurl -s https://api.github.com/repos/curl/curl | jq '{nama: .name, bintang: .stargazers_count, bahasa: .language}'
# Loop hasilcurl -s https://jsonplaceholder.typicode.com/posts | jq -r '.[:5][] | "\(.id): \(.title)"'
# Buat resource, lalu ambil ID dari responseID=$(curl -s -X POST https://jsonplaceholder.typicode.com/posts \ -H "Content-Type: application/json" \ -d '{"title":"tes","body":"isi","userId":1}' | jq -r .id)echo "ID baru: $ID"
# Pagination sederhanafor page in 1 2 3; do curl -s "https://api.example.com/items?page=$page" | jq -r '.items[].name'done
# GraphQLcurl -X POST https://api.example.com/graphql \ -H "Content-Type: application/json" \ -d '{"query":"{ user(id: 1) { name email } }"}'# IP publik kamucurl ifconfig.mecurl -s https://api.ipify.org?format=json
# Info geolokasi IPcurl -s https://ipinfo.io/8.8.8.8
# Cuaca di terminalcurl wttr.in/Jakartacurl "wttr.in/Jakarta?format=3"
# Kurs / cryptocurl -s "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd,idr"
# Cheat sheet via terminalcurl cheat.sh/tar
# Kirim notifikasi ke ntfy.shcurl -d "Build selesai" ntfy.sh/topik-rahasia-kamu
# Kirim pesan Telegram botcurl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \ -d chat_id="$CHAT_ID" -d text="Halo dari curl"
# Webhook Discordcurl -H "Content-Type: application/json" \ -d '{"content":"Deploy sukses 🚀"}' "$DISCORD_WEBHOOK_URL"
# Webhook Slackcurl -X POST -H "Content-type: application/json" \ --data '{"text":"Halo dari curl"}' "$SLACK_WEBHOOK_URL"
# GitHub API (dengan token)curl -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ https://api.github.com/user/repos
# Download release terbaru dari GitHubcurl -s https://api.github.com/repos/curl/curl/releases/latest | jq -r .tag_name
# Cek ketersediaan paket di npmcurl -s https://registry.npmjs.org/express/latest | jq -r .versionOther Protocol
# FTP: list direktoricurl ftp://ftp.example.com/ --user user:pass
# FTP: downloadcurl -O ftp://ftp.example.com/pub/file.txt --user user:pass
# FTP: hapus filecurl ftp://ftp.example.com/ --user user:pass -Q "DELE file.txt"
# SFTP dengan SSH keycurl --key ~/.ssh/id_ed25519 --user alex: sftp://example.com/home/alex/file.txt -O
# Kirim email via SMTPcurl --url "smtps://smtp.gmail.com:465" --ssl-reqd \ --mail-from "kamu@gmail.com" --mail-rcpt "tujuan@example.com" \ --user "kamu@gmail.com:app-password" \ -T email.txt
# Baca email via IMAPcurl --url "imaps://imap.gmail.com/INBOX" --user "kamu@gmail.com:app-password"
# Baca file lokalcurl file:///etc/hostname
# DICT (kamus)curl dict://dict.org/d:linux
# Telnet / raw TCPcurl telnet://example.com:80
# WebSocket (curl >= 8.11, eksperimental)curl --include --no-buffer ws://echo.websocket.org
# LDAPcurl "ldap://ldap.example.com/dc=example,dc=com?cn?sub?(objectClass=*)"Help
# mengecek versi curlcurl --version
# manual lengkapcurl --help allman curl- Jangan taruh password/token langsung di command kalau di mesin shared. Command tersimpan di shell history dan terlihat di
ps. Pakai variabel environment, ~/.netrc, atau -Kconfig file. -k / --insecuremematikan verifikasi TLS. Pakai hanya untuk testing, jangan di production.curl | shitu berisiko karena kamu menjalankan kode asing. Unduh dulu, baca isinya, baru jalankan.- Selalu kasih tanda kutip pada URL yang punya
&,?, atau karakter spesial, supaya tidak ditafsirkan shell.
Footnotes
Support & Share
If this article helped you, please share or support!












