Skip to main content
Glama
weather.ts1.41 kB
import axios from 'axios'; import { config } from '../config/index.js'; import type { WeatherData, ForecastData } from './types.js'; export class WeatherService { private readonly apiKey: string; private readonly apiBase: string; private readonly units: string; constructor() { if (!config.openWeather.apiKey) { throw new Error('OpenWeather API key is required'); } this.apiKey = config.openWeather.apiKey; this.apiBase = config.openWeather.apiBase; this.units = config.openWeather.units; } private async makeRequest<T>(endpoint: string, params: Record<string, any>): Promise<T | null> { try { const response = await axios.get(`${this.apiBase}/${endpoint}`, { params: { ...params, appid: this.apiKey, units: this.units } }); return response.data as T; } catch (error) { console.error("Error making OpenWeather request:", error); return null; } } async getCurrentWeather(city: string, country?: string): Promise<WeatherData | null> { const query = country ? `${city},${country}` : city; return this.makeRequest<WeatherData>("weather", { q: query }); } async getForecast(city: string, country?: string): Promise<ForecastData | null> { const query = country ? `${city},${country}` : city; return this.makeRequest<ForecastData>("forecast", { q: query }); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fist-maestro/mcp-servers'

If you have feedback or need assistance with the MCP directory API, please join our Discord server