cURL with API
Table of contents
Basic cURl
For more cURL command, click here.
curl -I https://jsonplaceholder.typicode.com/posts/3
-Ifor request header
curl -i https://jsonplaceholder.typicode.com/posts/3
-ifor header and content
Create file with cURL and open resource jsonplaceholder
- Change directory;
cd /example-folder. - Run cURL to generate
text.txtfile.
curl -o test.txt https://jsonplaceholder.typicode.com/posts
-ostands for--output. It writes the output content fromjsonplaceholdertotext.txt
Download with -O
Note: -O and -o, using capitalised O for download.
curl -O https://jsonplaceholder.typicode.com/posts
Download with limit using flag --limit-rate 1000B
curl -O --limit-rate 1000B https://jsonplaceholder.typicode.com/posts
Post data
-dstands for--data-Xflag specifies a HTTP request method when communicates with the remote server.
curl --data "title=Hello&body=hello world" https://jsonplaceholder.typicode.com/posts
curl -X POST https://jsonplaceholder.typicode.com/posts --data "title=Hello&body=hello world" | jq
Put request
curl -X PUT https://jsonplaceholder.typicode.com/posts/3 --data "title=hello"
Delete request
curl -X DELETE https://jsonplaceholder.typicode.com/posts
cURL with FTP (File Transfer Protocol)
The syntax is curl -u username:password https://xxxxx
Upload to FTP
curl -u FTPaccountname@domain.com:123456!(password) -T hello.txt ftp://ftp.domain.com
Download from FTP
curl -u FTPaccountname@domain.com:123456!(password) -O ftp://ftp.domain.com/hello.txt