API Code Examples

To make the whole integration process easy, we are providing code examples in different programming languages.

For latest code libraries visit our official Github World Weather Online page.

We have also launched a new Weather AI Decision API.

Quick start

Replace YOUR_API_KEY with your key. No key yet? Sign up and you get a 14-day free trial key straight away; logged-in users can also try every endpoint in the API explorer, where your key is filled in for you.

curl "https://api.worldweatheronline.com/premium/v1/weather.ashx?key=YOUR_API_KEY&q=London&format=json&num_of_days=3"
// Browser (keep your key server-side in production)
const url = "https://api.worldweatheronline.com/premium/v1/weather.ashx?key=YOUR_API_KEY&q=London&format=json&num_of_days=3";
const res = await fetch(url);
const data = await res.json();
const today = data.data.weather[0];
console.log(today.date, today.maxtempC, today.mintempC);
// Node.js 18+ (built-in fetch)
const params = new URLSearchParams({
  key: process.env.WWO_API_KEY,
  q: "London",
  format: "json",
  num_of_days: "3",
});
const res = await fetch("https://api.worldweatheronline.com/premium/v1/weather.ashx?" + params);
const { data } = await res.json();
console.log(data.current_condition[0].temp_C);
import os, requests

r = requests.get(
    "https://api.worldweatheronline.com/premium/v1/weather.ashx",
    params={"key": os.environ["WWO_API_KEY"], "q": "London", "format": "json", "num_of_days": 3},
    timeout=10,
)
r.raise_for_status()
for day in r.json()["data"]["weather"]:
    print(day["date"], day["maxtempC"], day["mintempC"])
<?php
$query = http_build_query([
    "key" => getenv("WWO_API_KEY"),
    "q" => "London",
    "format" => "json",
    "num_of_days" => 3,
]);
$json = file_get_contents("https://api.worldweatheronline.com/premium/v1/weather.ashx?" . $query);
$data = json_decode($json, true);
echo $data["data"]["current_condition"][0]["temp_C"];
using System.Net.Http.Json;
using System.Text.Json;

var key = Environment.GetEnvironmentVariable("WWO_API_KEY");
using var http = new HttpClient();
var url = $"https://api.worldweatheronline.com/premium/v1/weather.ashx?key={key}&q=London&format=json&num_of_days=3";
var doc = await http.GetFromJsonAsync<JsonDocument>(url);
var today = doc!.RootElement.GetProperty("data").GetProperty("weather")[0];
Console.WriteLine($"{today.GetProperty("date")}: {today.GetProperty("maxtempC")}C");
// Java 11+
var key = System.getenv("WWO_API_KEY");
var uri = java.net.URI.create("https://api.worldweatheronline.com/premium/v1/weather.ashx?key=" + key + "&q=London&format=json&num_of_days=3");
var client = java.net.http.HttpClient.newHttpClient();
var req = java.net.http.HttpRequest.newBuilder(uri).build();
var res = client.send(req, java.net.http.HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());

Other endpoints

The same pattern works for every Premium API; change the path and parameters.

APIExample request
Local weather forecast/premium/v1/weather.ashx?key=YOUR_API_KEY&q=48.85,2.35&num_of_days=7&tp=3&format=json
Historical weather (from July 2008)/premium/v1/past-weather.ashx?key=YOUR_API_KEY&q=London&date=2024-01-01&enddate=2024-01-31&tp=24&format=json
Marine weather/premium/v1/marine.ashx?key=YOUR_API_KEY&q=50.1,-5.5&tide=yes&format=json
Ski weather/premium/v1/ski.ashx?key=YOUR_API_KEY&q=Zermatt&format=json
Astronomy/premium/v1/astronomy.ashx?key=YOUR_API_KEY&q=London&date=today&format=json
Time zone/premium/v1/tz.ashx?key=YOUR_API_KEY&q=Tokyo&format=json
Location search/premium/v1/search.ashx?key=YOUR_API_KEY&query=Lond&num_of_results=5&format=json

All requests go to https://api.worldweatheronline.com. Full parameter lists are in the API documentation.

Libraries on GitHub

Community and older client libraries (check each for the API version it targets):

Disclaimer: The example codes are provided without any guarantee of reliability, accuracy of information, or correctness of operation. We are not responsible for any damage that may occur as a result of using these example codes. Use this program only for learning purpose and entirely at your own risk.

14 Day Free Trial

Sign up now, it only takes 1 minute
Sign Up

Download Our Apps