Invoking APIs from the Command Line using cURL

by Interzoid Team


Posted on August 20th, 2019


Use CURL to Invoke APIs Quickly and Easily to Understand Value and Build Applications

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:

{"Symbol":"EUR","Name":"Euro","Country":"European Union","Rate":"0.895","Code":"Success","Credits":"72250"}

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:

{"Converted":"11.30","Currency":"USD","Code":"Success","Credits":"93244"}

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:

{"City":"Columbus","State":"OH","TempF":"84.0","TempC":"28.9","Weather":"Fair","WindMPH":"11.5","WindDir":"South","RelativeHumidity":"63","VisibilityMiles":"10.00","Code":"Success","Credits":"18005"}

As you can see, cURL is an easy way to take any API for a test drive before putting it to use.


Free API Credits
Register for an Interzoid API account and receive free trial credits
Global Page Load API
Measure Web asset performance from multiple locations around the globe.
More Info...