Task 2: Explore the AccuWeather API
We will use an application called Postman to explore the AccuWeather API. Please refer to the Logistics document for instructions to download and install Postman on your computer.
Postman is an API Development Environment (ADE).
Postman was initially a Chrome extension designed to help developers explore APIs. Since then, it has matured into a stand-alone application, an industry standard for designing, documenting, testing, and interacting with APIs.
Step 1: Obtaining Location Key
Open Postman and click on the +
button to create a new API request.
Enter the request URL (i.e., an API endpoint) in the designated area.
Suppose we want to obtain the location key for a given city name using the AccuWeather API. To accomplish this, we must refer to the API reference for guidance. We can obtain the location key using the City Search endpoint within the Locations API.
According to the reference, the request URL is:
http://dataservice.accuweather.com/locations/v1/cities/search
In addition, we need to provide the apikey
and q
(short for "query") parameters. Please provide the required information, as shown in the image below.
Click on the "Send" button to send the request. It will take a moment, and then you will see the response.
Notice the response is in JSON format. It is an array of objects. Each object corresponds to a city or location that matched the name "Baltimore." Each location object contains information, including a "key" attribute. We need the "key" to get weather forecast data related to a location.
Step 2: Obtaining Current Conditions
In the previous step, we made an HTTP GET request.
HTTP stands for Hypertext Transfer Protocol, and it is used to structure requests and responses over the Internet.
We use four basic HTTP verbs (operations or methods) in requests to interact with an API: GET, POST, PUT, and DELETE. We will explore these in more detail in the future. For now, let's make another GET request.
The endpoint for this request is:
http://dataservice.accuweather.com/currentconditions/v1/:locationKey
Note that :locationKey
is a path parameter.
Notice that the value of :locationKey
is provided as 348707
, which is the location key of Baltimore, MD.
Click the "Send" button to send the request. It will take a moment, and then you will see the "response.”
Notice that the response includes the temperature.