Calling a weather API

Now it's time to get the weather data and display it on the page.

We will use XMLHttpRequest to achieve this. Register yourself at http://openweathermap.org/appid and get your application ID. Your application ID will be appended in the actual URL to make the authenticated call to the weather API. Once you get the app ID let's keep that information in the Constants.kt file: 

    const val IMAGE_URL = "http://openweathermap.org/img/w/%s.png"    const val BASE_URL =      "https://api.openweathermap.org/data/2.5/forecast/daily?         mode=json&units=metric&cnt=7"    const val APP_ID = "Your open weather map application id"    const val FULL_URL = "$BASE_URL&appid=$APP_ID&q="

The Constants.kt file is not as simple as it looks. Check how we have ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.