The curl command on Linux can be used to download files, as well as talk to Web APIs directly from the Linux shell. It is a very versatile command for programmers to test access to the APIs of software and applications hosted on the web.
The basic syntax of curl is:
Example:
In this way, it sends a GET request to the specified server on the provided page. Is it possible to pass GET parameters directly in the URL using the “tabs**?** “and” &”.
It is necessary when passing more than one parameter in the URL, especially using the ”& “symbol, to use single quotes in the URL:
Curl allows you to enter a timeout in seconds for which it will wait for a response from the server, with the option “-m “:
It is possible to make a POST call using curl, with the “-X” option:
The -X option allows the GET (default), POST, and PUT methods.
To send data in the POST request, the “-d” option must be used. The data must be in the URL encoded format.
You can also separate the data into multiple “-d” options:
It is also possible to specify a file containing the data for sending via POST, using the option “-d” with ”@ “:
If the site requires simple HTTP authentication, the “-u” option can send a username and password:
To send a JSON file, it is necessary to specify the HTTP header, with the option “-H “:
The “-i” option allows you to see the HTTP response from the server:
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.