Technical documentation for Weather Dashboard API integration
Weather Dashboard provides real-time weather data, forecasts, and city search capabilities through integration with the WeatherAPI service. The application makes client-side API requests to fetch weather information.
https://api.weatherapi.com/v1/
All API requests require an API key for authentication. The key is included as a query parameter:
?key=YOUR_API_KEY
Retrieve real-time weather data for a specified location.
/current.json
| Parameter | Type | Required | Description |
|---|---|---|---|
key |
string | Required | Your API key |
q |
string | Required | Location query (city name, coordinates, IP, etc.) |
aqi |
string | Optional | Include air quality data (yes/no). Default: no |
GET https://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q=Kolkata&aqi=yes
{
"location": {
"name": "Kolkata",
"region": "West Bengal",
"country": "India",
"lat": 22.57,
"lon": 88.37,
"tz_id": "Asia/Kolkata"
},
"current": {
"temp_c": 28.5,
"temp_f": 83.3,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png"
},
"wind_kph": 15.1,
"humidity": 72,
"feelslike_c": 31.2,
"uv": 6,
"air_quality": {
"us-epa-index": 3
}
}
}
Get weather forecast for up to 14 days.
/forecast.json
| Parameter | Type | Required | Description |
|---|---|---|---|
key |
string | Required | Your API key |
q |
string | Required | Location query |
days |
integer | Required | Number of forecast days (1-14) |
aqi |
string | Optional | Include air quality data |
alerts |
string | Optional | Include weather alerts |
GET https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q=Mumbai&days=7
Search for cities and get autocomplete suggestions.
/search.json
| Parameter | Type | Required | Description |
|---|---|---|---|
key |
string | Required | Your API key |
q |
string | Required | Search query (minimum 2 characters) |
GET https://api.weatherapi.com/v1/search.json?key=YOUR_API_KEY&q=Delh
[
{
"id": 2295019,
"name": "Delhi",
"region": "Delhi",
"country": "India",
"lat": 28.67,
"lon": 77.22,
"url": "delhi-delhi-india"
},
{
"id": 2295020,
"name": "New Delhi",
"region": "Delhi",
"country": "India",
"lat": 28.6,
"lon": 77.2,
"url": "new-delhi-delhi-india"
}
]
| Field | Type | Description |
|---|---|---|
name |
string | City/location name |
region |
string | State/province name |
country |
string | Country name |
lat |
number | Latitude coordinate |
lon |
number | Longitude coordinate |
tz_id |
string | Timezone identifier |
localtime |
string | Local date and time |
| Field | Type | Description |
|---|---|---|
temp_c |
number | Temperature in Celsius |
temp_f |
number | Temperature in Fahrenheit |
condition |
object | Weather condition details |
wind_kph |
number | Wind speed in km/h |
humidity |
number | Humidity percentage |
feelslike_c |
number | Feels like temperature in Celsius |
uv |
number | UV index |
vis_km |
number | Visibility in kilometers |
pressure_mb |
number | Atmospheric pressure in millibars |
gust_kph |
number | Wind gust speed in km/h |
WeatherAPI implements rate limiting based on your subscription plan:
| Code | Message | Description |
|---|---|---|
400 |
Bad Request | Invalid parameters or malformed request |
401 |
Unauthorized | Invalid API key |
403 |
Forbidden | API key disabled or exceeded quota |
404 |
Not Found | Location not found |
500 |
Internal Server Error | Server-side error |
{
"error": {
"code": 1006,
"message": "No matching location found."
}
}
async function fetchCurrentWeather(city) {
const apiKey = 'YOUR_API_KEY';
const url = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${city}&aqi=yes`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching weather:', error);
throw error;
}
}
// Usage
fetchCurrentWeather('Kolkata')
.then(data => console.log(data))
.catch(error => console.error(error));