curl
Transfer danych przez HTTP, FTP, SFTP, ...
Opis
curl to najpotężniejsze narzędzie do testowania API. HTTP methods, headers, auth, redirects, proxies, upload, download. Zastępuje wget w 95% przypadków.
Przykłady
$ curl -s https://api.github.com/repos/torvalds/linux | jq .stargazers_count
Liczba gwiazdek repo Linux
$ curl -X POST -H 'Content-Type: application/json' -d '{"a":1}' https://api.example.com
POST z JSON
$ curl -u user:pass -O https://example.com/file.zip
Basic auth + download
$ curl -F 'file=@photo.jpg' https://api.example.com/upload
Multipart form upload
$ curl -w '%{http_code} %{time_total}s\n' -o /dev/null -s https://example.com
HTTP code + czas
$ curl --head https://example.com
Tylko headers (HEAD)
Flagi
| Flaga | Opis |
|---|---|
-s |
Silent (bez progress) |
-S |
Silent + errors |
-X |
HTTP method (GET, POST, ...) |
-H |
Nagłówek HTTP |
-d |
Data w body |
-F |
Multipart form |
-u |
Basic auth (user:pass) |
-o |
Zapisz do pliku |
-L |
Follow redirects |
-k |
Ignore SSL errors |
-w |
Write-out (format po zakończeniu) |
--head |
Tylko headers |