A GraphQL-based weather API built with Go that fetches real-time and historical weather data from Visual Crossing. The API supports querying by city and optional date, caches responses using Redis, and applies rate limiting using API keys to prevent abuse. This is my project following https://roadmap.sh/projects/weather-api-wrapper-service.
- 🔍 GraphQL API using
gqlgen - 🌦️ Fetch weather data by city and optional date (defaults to today)
- ⚡ Caching with Redis to avoid redundant external API calls
- 🛡️ Rate Limiting based on API keys to prevent abuse
- 📆 Query by City & Date (defaults to current date if not provided)
- 🐳 Docker-based Redis setup
- 🛠️ Developer-friendly with VSCode debug support
- ✅ Go installed (Download Go)
- ✅ Docker installed (Install Docker)
- ✅ Redis running locally (or via Docker)
- ✅ Visual Crossing API Key from: https://www.visualcrossing.com
git clone https://github.com/Agarwalsahil/weather-api.git
cd weather-apigo mod tidygo run github.com/99designs/gqlgen generate# 💻 On Linux/macOS:
export WEATHER_API_KEY=your_key_here
# 🪟 On Windows (cmd):
set WEATHER_API_KEY=your_key_herego run server.goServer starts on: http://localhost:8080
{
"version": "0.2.0",
"configurations": [
{
"name": "weather-api",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/server.go",
"env": {
"WEATHER_API_KEY": "Your Api Key"
},
"args": []
}
]
}query {
getWeatherData(city: "New Delhi") {
latitude
longitude
resolvedAddress
days {
temp
tempmax
windgust
windspeed
}
isProcessed
}
}- Key:
${city}:${date} - Checks Redis cache first.
- If not found → Fetch from external API → Store result in cache → Return response.
-
API key must be passed in request headers:
{ "X-API-Key": "your-api-key" } -
Requests without valid API key are denied.
-
Rate limits configurable (e.g., max 5 req/min per key).
docker run --name weather-api-redis -p 6379:6379 -d redisPull requests are welcome! For major changes, open an issue first to discuss what you'd like to change.
Built with ❤️ using Go and GraphQL
By [Sahil Agarwal]
