Link Search Menu Expand Document

cURL with API

Table of contents

Basic cURl

For more cURL command, click here.

curl -I https://jsonplaceholder.typicode.com/posts/3

-I for request header

curl -i https://jsonplaceholder.typicode.com/posts/3

-i for header and content

Create file with cURL and open resource jsonplaceholder

  1. Change directory; cd /example-folder.
  2. Run cURL to generate text.txt file.
curl -o test.txt https://jsonplaceholder.typicode.com/posts
  • -o stands for --output. It writes the output content from jsonplaceholder to text.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

  • -d stands for --data
  • -X flag 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