LoslegenKostenlos starten

Weather API: invoking and formatting a response

Modern apps often fetch data from a web API and then shape the response before showing it to users. In this exercise, you'll simulate calling a weather API for two cities and produce a single JSON payload with a parent key. This mirrors sending a GET request and rendering the resulting JSON.

Diese Übung ist Teil des Kurses

<Kurs>Azure API Management</Kurs>
Kurs ansehen

Übungsanweisungen

  • Use the provided API to fetch current weather for London and Paris.
  • Combine the two results into one response object grouped under a single parent key.
  • Print the JSON response.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Fetch weather for two cities
london_weather = get_weather('____')
paris_weather = get_weather('____')

# Combine under a parent key
payload = {'weather': [____, ____]}

print("Current weather report:")
respond(____)
Code bearbeiten und ausführen