curl
- transfer data to and from the web. With curl
you can easily interact with REST API.
Syntax
Options
Common Option |
Description |
-O |
write output to a local file named like the remote file we got |
-o file |
write output to file instead of stdout |
-i/--include |
fetch the HTTP header in the output |
-I/--head |
fetch the HTTP header only |
-H header |
Extra header to use when getting a web page. |
-X Http_Method |
Specifies a custom request method to use when communicating with the HTTP server. |
-d/--data data |
send POST request to HTTP server with data |
-L |
follow redirect. redirect happens when server response is 3xx |
-k |
(SSL) This option explicitly allows curl to perform “insecure” SSL connections and transfers. |
-u user:password |
specify user name and password to use server authentication |
--retry num |
retry num times |
--retry-delay seconds |
set retry delay in seconds |
-s |
Silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute. |
Examples
Download file
Download file in silent mode
1
| curl -s -O https://github-media-downloads.s3.amazonaws.com/Octocats.zip
|
You can also use -o to rename the downloaded file
1
| curl -s -o funny-octocats.zip https://github-media-downloads.s3.amazonaws.com/Octocats.zip
|
Curl with Basic authentication
1
| curl -u username:password http://mydomain.com
|
Make a GET Request
send a GET request to server and display response
1
| curl http://127.0.0.1:5984/demo
|
Same as
1
| curl -X GET http://127.0.0.1:5984/demo
|
1
| curl -i -X GET http://127.0.0.1:5984/demo
|
Make a PUT Request
1
| curl -X PUT http://172.17.0.4/newdb
|
Make a POST Request
Make a Post request to create a customer
1
| curl -X POST -H 'Content-Type: application/json' http://localhost:8080/customers/ -d '{"name": "Dave", "age": "25"}'
|
Reference