O'Reilly logo

TypeScript Blueprints by Ivo Gabe de Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Showing a forecast

We still have not shown a forecast yet. We will use data from open weather map (http://www.openweathermap.org). You can create an account on their website. With your account, you can request an API token. You need the token to request the forecast. A free account is limited to 60 requests per second and 50,000 requests per day.

We save the API token in a separate file, lib/config.ts:

export const openWeatherMapKey = "your-token-here"; 
export const apiURL = "http://api.openweathermap.org/data/2.5/"; 

Tip

Add constants to a separate file

When you add constants in separate configuration files, you can easily change them and your code is more readable. This gives you better maintainable code.

Using the API

We will create a new file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required