Search results

Make a curl call

In this section, you’ll use curl to make the same weather API requests you made previously with Postman. If you haven’t installed curl, see curl intro and installation first.

Prepare the weather request in curl format

  1. Assuming you completed the exercises in the Postman tutorial, go back into Postman.
  2. On any call you’ve configured, right below the Save button in Postman, click the Code link, then select cURL from the drop-down select, and click Copy to Clipboard.

    (The official name is “cURL” but most people just write it as “curl.”)

    The code for the OpenWeatherMap weather request looks like this in curl format:

    curl -X GET -H "Cache-Control: no-cache" -H "Postman-Token: 930d08d6-7b2a-6ea2-0725-27324755c684" ""

    For whatever reason, Postman adds some of its own header information (designated with -H). Remove these extra header tags.

    curl -X GET ""
  3. If you’re on a Mac, open Terminal by pressing Cmd + space bar and typing Terminal. Paste the request you have in your text editor into the command line and then press the Enter key.

    Mac users: Instead of using Terminal, download and use iTerm instead. It will give you the ability to open multiple tabs, save profiles, and more.

  4. If you’re on Windows, go to Start and type cmd to open up the command line. (If you’re on Windows 8, see these instructions for accessing the commandline.) Right-click and then select Paste to insert the call.

    The response from the OpenWeatherMap weather request should look as follows:

    {"coord":{"lon":-121.96,"lat":37.35},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":65.59,"pressure":1014,"humidity":46,"temp_min":60.8,"temp_max":69.8},"visibility":16093,"wind":{"speed":4.7,"deg":270},"clouds":{"all":20},"dt":1522608960,"sys":{"type":1,"id":479,"message":0.1642,"country":"US","sunrise":1522590719,"sunset":1522636280},"id":420006397,"name":"Santa Clara","cod":200}

    This response is minified. You can un-minify it by going to a site such as JSON pretty print, or on a Mac (with Python installed) you can add | python -m json.tool at the end of your cURL request to minify the JSON in the response. See this Stack Overflow thread for details.

Make curl requests for each of the Postman requests


Make a curl request for each of the requests you entered in Postman.

Note about single and double quotes with Windows curl requests

If you’re using Windows to submit a lot of curl requests, and the curl request require you to submit JSON in the request body, you might run into issues with single versus double quotes. Some API endpoints (usually for POST methods) require you to submit content in the body of the message request. The body content is formatted in JSON. Since you can’t use double quotes inside of other double quotes, you’ll run into issues in submitting curl requests in these scenarios.

Here’s the workaround. If you have to submit body content in JSON, you can store the content in a JSON file. Then you reference the file with an @ symbol, like this:

curl -H "Content-Type: application/json" -H "Authorization: 123" -X POST -d @mypostbody.json

Here curl will look in the existing directory for the mypostbody.json file. (You can also reference the complete path to the JSON file on your machine.)

15% Complete

15/101 pages complete. Only 86 more pages to go...


If you would like to contribute back to say thank you for the API documentation course, click the Donate button below. Alternatively, to contribute content, such as a tutorial or a new section, contact me with your ideas. You can also submit a pull request in the GitHub repo to make your contribution. Even if you want to just fix a typo or add a sentence here and there, it's always welcome.

Get new posts delivered straight to your inbox.

Subscriber count: 4,285