Curl

Introduction

Curl is an open source utility for executing APIs from the command line. It has been in continuous usage since 1997, and over time has gathered wide support. It currently offers a rich set of command line options, and supports all the common network protocols.

Installing Curl

Curl comes installed on recent Mac and Windows 10 systems by default. For those who need to download it, there are a couple of approaches:

If you already have Git Bash installed, you can run Curl commands directly from a Git Bash window, without having to install anything else.

Curl for Windows can also be downloaded from the Curl download site here: https://curl.haxx.se/windows/.

Command Line Options

Curl is certainly “Old School”, and can be a bit intimidating to someone used to working with APIs through a user interface. However once you’re familiar with it, it’s not that hard to use.

The basic layout of a Curl command is:

curl <list of command options> <url>

It’s the list of command options that you include in the command that largely controls its behavior. If you wish to see all the possible options, you can list them with: curl –help. As the list is quite long, here are some of the more useful options.:

-d, –data <data> HTTP POST data (i.e. the data payload for a post request)

-i, –include Include response headers in the output

-I, –head Show document info only (i.e. just the header)

-K, –config <file> Read config from a file (i.e. get options from a file)

-o, –output <file> Write response to a file instead of stdout

-O, –remote-name Write output to a file named as the remote file (i.e download a file)

-u, –user <user:password> Server user and password (authentication)

-v, –verbose Make the operation more talkative

-X, –request <command> Specify request command to use (i.e. a PUT command is: -X PUT)

Learning Curl

Of course you can practice using Curl against the Keep APIs. However there is also the JSONPlaceholder site (in the Resources below) that provides a safe online REST API site full of fake data, that you can use to test your Curl skills.

Curl Resources

Curl Home Page: https://curl.haxx.se/

Curl Documentation Page: https://curl.haxx.se/docs/

Basic Curl Tutorial: https://www.youtube.com/watch?v=iLVoA1DTE60

Another Curl Tutorial: https://www.youtube.com/watch?v=7XUibDYw4mc

JSONPlaceholder (fake data): https://jsonplaceholder.typicode.com/