4. Introduction to cURL - ShakthiSampath/Learning-Angular.io GitHub Wiki
cURL
Introduction
CURL is a Command Line Tool to transfer data from or to a server using the support of various protocols. The various protocols used are:
DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP.
By default, the result is displayed on the terminal but we can even save the data inside a file. We can even download images from servers. There are various other features which will be explained further.
Features
- Supports many protocols
- SSL Support and many authentication methods
- For downloads, you can even mention range
- Multiple URL support (All in the same connection)
- Library of its own LIBCURL (Stable API)- So that can be used with multiple and scripting languages to do web scraping better
- Even large files more than 2GB can be downloaded
Probably the reasons to be used
Demo
We will be using a website which provides fake online REST API for demo purpose.
To display data
curl https://jsonplaceholder.typcode.com/posts
Example with id = 3
To create a file having the data
curl -o data.txt curl https://jsonplaceholder.typcode.com/posts
cat data.txt
Downloading Images and Files
curl -O https://ichef-1.bbci.co.uk/news/660/cpsprodpb/E9DF/production/_96317895_gettyimages-164067218.jpg
Even Limit file download size
curl -O --limit-rate 1M https://ichef-1.bbci.co.uk/news/660/cpsprodpb/E9DF/production/_96317895_gettyimages-164067218.jpg
Few HTTP requests - Do a POST request
curl --data "title=Hello&body=Hello World" https://jsonplaceholder.typcode.com/posts
Do a PUT request
curl -X PUT -d "title=OlleH" https://jsonplaceholder.typcode.com/posts/101
Do a DELETE request
curl -X DELETE https://jsonplaceholder.typcode.com/posts/101