Backend API for fetching current weather data from WeatherAPI with Redis caching.
- Go Fiber HTTP server
- POST endpoint to fetch current weather by city
- Redis cache (10 minute TTL per city)
- Graceful shutdown (closes Redis client on SIGINT/SIGTERM)
- Go (see
go.modfor the version) - A WeatherAPI key (
WEATHER_API_KEY) - Redis (local install or Docker)
The server loads environment variables from a .env file if present (optional).
WEATHER_API_KEY: your WeatherAPI key (required)REDIS_URL: Redis connection URL (required)- Example (local):
redis://localhost:6379/0 - Example (Docker Compose):
redis://redis:6379/0
- Example (local):
- Start Redis (example with Docker):
docker run --rm -p 6379:6379 redis:7-alpine- Create a
.envfile:
WEATHER_API_KEY=your_key_here
REDIS_URL=redis://localhost:6379/0- Run the server:
go run .The server listens on http://localhost:3000.
This repo includes docker-compose.yml and a Dockerfile.
- Create a
.envfile (Compose will read it automatically):
WEATHER_API_KEY=your_key_here
REDIS_PASSWORD=- Start everything:
docker compose up --buildThe app code expects REDIS_URL (a URL like redis://redis:6379/0). If your Compose setup isn’t working, ensure the container gets REDIS_URL (the current docker-compose.yml uses REDIS_ADDR, which the app does not read).
- GET
/ - Response:
Hello, World!
- POST
/weather/current - Body:
{ "city": "London" }- Example:
curl -sS -X POST "http://localhost:3000/weather/current" \
-H "Content-Type: application/json" \
-d '{"city":"London"}'main.go restricts CORS to https://vaayu-weather-app.vercel.app/. For local frontend development, you may need to update AllowOrigins (for example, to include http://localhost:5173).