Curl

The curl project provides two tools, the libcurl library and the curl command line tool.

The first is a client-side URL transfer library that supports a whole host of protocols. The curl tool can be used for getting and sending data with a URL syntax and uses libcurl under the hood.

When you install curl, you get both tools and can use the curl command to perform requests and read the results. We will use curl in some places to perform HTTP(s) calls, mostly to perform REST requests. You will be provided with the basic commands you can copy and paste to use curl.

GUI Alternatives

If you prefer a GUI tool over a command line tool, Postman is one of the best-known ones. You can also install an extension to most browsers that will offer similar functionality - these are normally called REST Client or something similar. Yet Another REST Client is an example of an extension for Chromium based browsers. Most IDEs also have some functionality to perform requests and inspect the results. For VSCode, the REST Client extension is a good option.

Formatting JSON

Many of the requests we’ll perform return JSON by default. Reading JSON in plain text is a bit cumbersome, so there are additional tools you can use to improve the experience, if you want to. One of those tools is jq. jq is a very powerful tool and has a lot of functionality, but for the use cases in the training, simply passing the JSON from the call you’ve performed into jq is probably enough. For instance, you could use jq in this manner on a MacOS or Linux system.

curl https://headers.jsontest.com | jq

Instead of the plain text output, the result is now coloured (and formatted, although this particular service already does that as a convenience), making it easier to read.

jq example formatting
Figure 1. Example of JSON output formatted with jq

If you want to, you can additionally install jq for use during the assignments. It’s an optional addition to make your life just a little bit easier! More information on installing jq can be found on its website.

Windows

For Windows, you can also install Git Bash, a GUI tool that incorporates some command line tools, such as the Bourne Again Shell (bash) and git itself.

The curl program is pre-installed for Windows 10 and 11. Test whether you can use curl by going to your terminal application and run the following command.

$ curl -V

Note that the -V flag is a capital letter V. You should see the version information of the curl program being printed.

Example output of curl -V
curl 8.0.1 (Windows) libcurl/8.0.1 Schannel WinIDN
Release-Date: 2023-03-20
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets
If you get a message that the curl program cannot be found, install it first from the website.

Check that you can access a URL with another curl command.

$ curl http://www.example.com

The result will be the HTTP headers returned by the website, if the command is successful.

Example output of curl -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 114546
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Wed, 23 Aug 2023 06:55:00 GMT
Etag: "3147526947"
Expires: Wed, 30 Aug 2023 08:11:23 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (nyb/1D06)
X-Cache: HIT
Content-Length: 1256
Strict-Transport-Security: max-age=157680000

That’s it for curl!