Step 10

We want to implement getLocationKey and getCurrentCondition function. These functions should call AccuWeather API similar to what we have done in Postman. In JavaScript, we can use the Fetch Web API to make HTTP requests.

The Fetch API provides a JavaScript interface for making HTTP requests. In its simplest form, its syntax looks like this

fetch('/some/api/endpoint/')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(err => console.log(err))

Calling fetch() returns a promise. We can then wait for the promise to resolve. Once resolved, the response will be available within the promise's then() method.

Using fetch() is an example of retrieving resources asynchronously across the network.

We will explore JavaScript's asynchronous behavior in the near future.

Resources