curl intro and installation
While Postman is convenient, it’s hard to use it to represent how to make calls with it in your documentation. Additionally, different users probably use different GUI clients, or none at all (preferring the command line instead).
Instead of describing how to make REST calls using a GUI client like Postman, the most conventional method for documenting request syntax is to use curl.
- About curl
- Installing curl
- Make a test API call
curl is a command-line utility that lets you execute HTTP requests with different parameters and methods. Instead of going to web resources in a browser’s address bar, you can use the command line to get these same resources, retrieved as text.
Sometimes curl is written as cURL. It stands for Client URL. “curl” is the more common convention for its spelling, but both refer to the same thing.
curl is usually available by default on Macs but requires some installation on Windows. Follow these instructions for installing curl:
Install curl on Mac
If you have a Mac, by default, curl is probably already installed. To check:
- Open Terminal (press Cmd + spacebar to open Finder, and then type “Terminal”).
In Terminal type
curl -V. The response should look something like this:
curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets
If you don’t see this, you need to download and install curl.
Install curl on Windows
Installing curl on Windows involves a few more steps. First, determine whether you have 32-bit or 64-bit Windows by right-clicking Computer and selecting Properties. Then follow the instructions in this Confused by Code page. Most likely, you’ll want to choose the With Administrator Privileges (free) installer.
After you install curl, test your version of curl by doing the following:
- Open a command prompt by clicking the Start button and typing cmd.
The response should be as follows:
curl 7.54.0 (x86_64-apple-darwin14.0) libcurl/7.37.1 SecureTransport zlib/1.2.5 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IPv6 Largefile NTLM NTLM_WB SSL libz
Make a test API call
After you have curl installed, make a test API call:
curl -X GET "https://api.openweathermap.org/data/2.5/weather?zip=95050&appid=APIKEY&units=imperial"
(In the above code, replace
APIKEY with your actual API key.)
You should get minified JSON response back like this:
In Windows, Ctrl+ V doesn’t work; instead, you right-click and then select Paste.
Notes about using curl with Windows
If you’re using Windows, note the following formatting requirements when using curl:
- Use double quotes in the Windows command line. (Windows doesn’t support single quotes.)
- Don’t use backslashes (
\) to separate lines. (This is for readability only and doesn’t affect the call on Macs.)
- By adding
-kin the curl command, you can bypass curl’s security certificate, which may or may not be necessary.
About Tom Johnson
I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.
If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.
17/177 pages complete. Only 160 more pages to go.