Posted on August 20th, 2019
cUrl, which stands for "client URL", is a command-line utility for sending and receiving data. It works with a wide range of protocols including http, https, and ftp. This makes it an ideal tool for executing and testing APIs without having to write any code, enabling a potential API consumer to get comfortable with a given API and easily discover and understand its behavior and value without a significant time investment. And while its beauty is in its simplicity, it can also be used in advanced ways such as enabling proxy support, performing FTP uploads, HTTP post commands, multiple forms of user authentication, and a whole lot more.
The tool works from the Command Line in most flavors of Linux, the Command Prompt in Windows, the Terminal in MacOS X, and other implementations of a Unix shell command line such as Bash.
To ensure that you have it installed on your machine, go to the command line and enter the following:
$ curl --version
In the unlikely event you don't already have it installed, get it from here.
For detailed usage information, you can read the documentation by entering the following:
$ curl --man
or in Windows:
> curl --help
For now however, let's keep things simple and execute some APIs from the command line. In these examples we will be using various APIs from Interzoid. You will need an API key from Interzoid, which only requires your email address to register and obtain one. Use your own API key when you see YOURAPIKEY in the code.
Note in the examples below, we will be using single quotes around the URL in the cURL API calls. This is a requirement for APIs with multiple parameters. In the case of Windows, you must use double quotes around the URL.
In this example, we will be obtaining a real-time currency quote from Interzoid's Get Currency Rate API. Simply enter the following from the command-line:
$ curl 'https://api.interzoid.com/getcurrencyrate?license=YOURAPIKEY&symbol=EUR'
or in Windows (this is the only time we will show the Windows variant syntax):
> curl "https://api.interzoid.com/getcurrencyrate?license=YOURAPIKEY&symbol=EUR"
And here is the JSON data retrieved and returned from the API:
In this example, we will perform a currency conversion using the Convert Currency API:
$ curl 'https://api.interzoid.com/convertcurrency?license=YOURAPIKEY&from=eur&to=usd&amount=10'
JSON data in response:
Here is an example of the Get Weather by Zip Code API:
$ curl 'https://api.interzoid.com/getweatherzipcode?license=YOURAPIKEY&zip=43210'
And the response:
As you can see, cURL is an easy way to take any API for a test drive before putting it to use.