Current weather for a city
O endpoint /weather retorna as condicoes climaticas atuais de qualquer cidade do mundo. Voce pode especificar unidades (metric, imperial) e idioma da descricao. A resposta inclui temperatura, umidade, vento, pressao, visibilidade, nascer e por do sol.
The /weather endpoint returns current weather conditions for any city in the world. You can specify units (metric, imperial) and description language. The response includes temperature, humidity, wind, pressure, visibility, sunrise and sunset times.
O endpoint recebe o nome da cidade, unidades e idioma:
const API_KEY = 'YOUR_API_KEY';
const BASE = 'https://weather.api.insyde.one';
async function getCurrentWeather(city, units = 'metric', lang = 'pt_br') {
const url = `${BASE}/weather?q=${city}&units=${units}&lang=${lang}&key=${API_KEY}`;
const res = await fetch(url);
return res.json();
}
const weather = await getCurrentWeather('São Paulo,BR');
| Campo / Field | Tipo / Type | Descricao / Description |
|---|---|---|
main.temp | number | Temperatura atual em graus / Current temperature in degrees |
main.feels_like | number | Sensacao termica / Feels-like temperature |
main.humidity | number | Umidade relativa (%) / Relative humidity (%) |
main.temp_min | number | Temperatura minima / Minimum temperature |
main.temp_max | number | Temperatura maxima / Maximum temperature |
wind.speed | number | Velocidade do vento (m/s ou mph) / Wind speed |
wind.deg | number | Direcao do vento em graus / Wind direction in degrees |
weather[0].description | string | Descricao do clima no idioma escolhido / Weather description in chosen language |
weather[0].icon | string | Codigo do icone / Icon code |
sys.sunrise | number | Horario do nascer do sol (Unix UTC) / Sunrise time (Unix UTC) |
sys.sunset | number | Horario do por do sol (Unix UTC) / Sunset time (Unix UTC) |
units=metric para Celsius e m/s, ou units=imperial para Fahrenheit e mph. O icone pode ser carregado em https://weather.api.insyde.one/icon/{code}.png.
units=metric for Celsius and m/s, or units=imperial for Fahrenheit and mph. Icons can be loaded from https://weather.api.insyde.one/icon/{code}.png.
Exemplo de resposta para Sao Paulo com unidades metricas e idioma portugues:
{
"weather": [
{
"id": 802,
"main": "Clouds",
"description": "nublado",
"icon": "03d"
}
],
"main": {
"temp": 28.4,
"feels_like": 31.2,
"temp_min": 24.1,
"temp_max": 32.0,
"pressure": 1012,
"humidity": 72
},
"visibility": 10000,
"wind": {
"speed": 3.4,
"deg": 220
},
"clouds": {
"all": 40
},
"sys": {
"sunrise": 1708416000,
"sunset": 1708462800
},
"name": "São Paulo"
}
async function showWeatherCard(city) {
const data = await getCurrentWeather(city, 'metric', 'pt_br');
const temp = Math.round(data.main.temp);
const feels = Math.round(data.main.feels_like);
const desc = data.weather[0].description;
const icon = data.weather[0].icon;
const iconUrl = `https://weather.api.insyde.one/icon/${icon}.png`;
// Wind speed m/s to km/h
const windKmh = Math.round(data.wind.speed * 3.6);
// Wind direction degrees to cardinal
const dirs = ['N','NE','E','SE','S','SW','W','NW'];
const windDir = dirs[Math.round(data.wind.deg / 45) % 8];
// Format sunrise/sunset
const sunrise = new Date(data.sys.sunrise * 1000)
.toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' });
const sunset = new Date(data.sys.sunset * 1000)
.toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' });
console.log(`${data.name} — ${temp}°C (${desc})`);
console.log(`Sensacao: ${feels}°C | Umidade: ${data.main.humidity}%`);
console.log(`Vento: ${windKmh} km/h ${windDir}`);
console.log(`Nascer: ${sunrise} | Por do sol: ${sunset}`);
}
showWeatherCard('São Paulo,BR');