Project URL: https://roadmap.sh/projects/weather-api-wrapper-service
A backend API that acts as a proxy and cache in front of the Visual Crossing weather API. A client asks for the weather in a city; the server checks a Redis cache first, and only calls Visual Crossing when there's no fresh answer already cached.
GET /weather/:cityCode— current weather for a cityGET /health— basic liveness check- Redis caching (cache-aside pattern) with a configurable TTL
- Rate limiting per IP
- Structured error responses (
400/404/502) instead of generic failures
- Node.js
- Redis running locally (or accessible via a connection URL)
- A free Visual Crossing API key
-
Clone the repo and install dependencies:
git clone git@github.com:tuanhoang0117/WeatherAPI.git cd WeatherAPI npm install -
Copy the example environment file and fill in your own values:
cp .env.example .envVariable Purpose WEATHER_API_KEYYour Visual Crossing API key REDIS_URLRedis connection string (defaults to redis://localhost:6379)PORTPort the server listens on (defaults to 3000)CACHE_TTL_SECONDSHow long cached weather data stays valid -
Make sure Redis is running:
redis-cli pingShould return
PONG. -
Start the server:
npm start
GET /health
GET /weather/:cityCode
GET /health returns { "status": "OK" } with no parameters — used to confirm the server itself is running, independent of Redis or Visual Crossing.
Example:
curl http://localhost:3000/weather/Sacramento
Success response — 200 OK
{
"city": "Sacramento",
"temperature": 85.7,
"unit": "F",
"conditions": "Clear"
}Error responses
400 Bad Request— missing or empty city code404 Not Found— city not recognized by Visual Crossing429 Too Many Requests— rate limit exceeded502 Bad Gateway— Visual Crossing is unreachable or erroring
All error responses share the same shape: { "error": "..." }.
Backend endpoints were manually tested using Postman, including:
- Successful requests against real cities
- Cache-hit vs. cache-miss response times
- Error cases (
400,404,502) - Rate limiting (
429) via Postman's Collection Runner
- Node.js + Express
- axios — HTTP client for calling Visual Crossing
- ioredis — Redis client
- express-rate-limit — rate limiting middleware
- dotenv — environment variable loading