What is Postman?
Postman is an API platform for building and using APIs, and generating API documentation.
Postman is known as a GUI REST client, meaning it has a graphical user interface and can invoke REST services.
For this exercise, we will use Postman to make a GET
request for the weather using the OpenWeatherMap API.
To use this API, you must create an account and create an API key
.
How to make a request with Postman
- Download and install Postman.
- Open Postman.
- Click New.
- Click HTTP Request.
-
Insert the following endpoint into the empty box ("Enter request URL") next to GET:
https://api.openweathermap.org/data/2.5/weather
-
Click on the tab labelled Params (parameters). It should be displayed by default.
-
Add the following parameters in the respective key and value rows:
- key:
zip
/ value:28215
- key:
units
/ value:imperial
- key:
appid
/ value: /e326886bb536c5eac65ccc70df1067bb
Note: When you add these parameters, they appear as a query string to the endpoint URL in the GET box. The endpoint now looks like this:
https://api.openweathermap.org/data/2.5/weather?zip=28215&units=imperial&appid=e326886bb536c5eac65ccc70df1067bb
- key:
-
Click Send.
Success
The response (in JSON) appears in the lower pane:
{
"coord":{
"lon":-80.7387,
"lat":35.244
},
"weather":[
{
"id":803,
"main":"Clouds",
"description":"broken clouds",
"icon":"04d"
}
],
"base":"stations",
"main":{
"temp":56.53,
"feels_like":55.74,
"temp_min":54.23,
"temp_max":59.4,
"pressure":1026,
"humidity":82
},
"visibility":10000,
"wind":{
"speed":8.05,
"deg":10
},
"clouds":{
"all":75
},
"dt":1665408709,
"sys":{
"type":2,
"id":2011045,
"country":"US",
"sunrise":1665401084,
"sunset":1665442490
},
"timezone":-14400,
"id":0,
"name":"Charlotte",
"cod":200
}
How to make the same request with curl
- In Postman, click on the code (< / >) button.
- Below Code Snippet, select cURL from the dropdown.
- Copy the code using the Copy snippet button.
- Paste the code into the command line.
- Replace the single-quotes around the hyperlink with double-quotes to avoid an error message:
curl --location --request GET "https://api.openweathermap.org/data/2.5/weather?zip=28215&units=imperial&appid=e326886bb536c5eac65ccc70df1067bb"
Success
The unminified (unformatted) response should look like this:
{"coord":{"lon":-80.7387,"lat":35.244},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"stations","main":{"temp":64.02,"feels_like":63.32,"temp_min":60.94,"temp_max":66.99,"pressure":1027,"humidity":68},"visibility":10000,"wind":{"speed":10.36,"deg":70},"clouds":{"all":40},"dt":1665416552,"sys":{"type":2,"id":2011045,"country":"US","sunrise":1665401084,"sunset":1665442490},"timezone":-14400,"id":0,"name":"Charlotte","cod":200}
How to save a request with Postman
- In Postman, click the Save button. It is above the Send button.
- In the Request name box, replace the endpoint with:
OpenWeatherMap Current API
. - Click the Add Description box.
- Type a description: “gets the current weather for 28215 in imperial units.”
- Scroll down and click New Collection to create a new folder to save the request in.
- Type the name of your new collection (“OpenWeatherMap”) in the Name your collection box.
- Click Create.
- Click the orange Save button.
Success
The request has been saved and will now appear in the left-side pane in the Collections tab.
How to create a Run in Postman button
- Click on the Collections tab in the left-side pane.
- Next to the collection name, select the more actions icon (three dots) and then click Share.
- Click on the Via Run in Postman tab.
- Click Embed a static version.
- Click on the Markdown friendly option.
- Click Copy code and embed the code below: