Skip to content

Conversation

@aditya241104
Copy link
Contributor

@aditya241104 aditya241104 commented Oct 13, 2025

Description

Extracts weather API call logic from Weather.jsx component into a dedicated service file and implements caching to reduce redundant API calls as requested in issue #23.

Changes Made

  • ✅ Created /src/services/weather.js service file
  • ✅ Moved all API logic from Weather.jsx to the new service
  • ✅ Implemented in-memory caching with 10-minute expiration
  • ✅ Added cache management utilities (clearWeatherCache, getCacheStats)
  • ✅ Maintained existing error handling and component behavior
  • ✅ Used existing wttr.in API endpoint with same functionality

How It Works

  • First request for a city: Fetches fresh data from wttr.in API
  • Subsequent requests for same city (within 10 min): Uses cached data
  • Cache expiration: Automatically expires after 10 minutes
  • Performance: Reduces redundant API calls and improves response time

File Structure

src/
services/
weather.js # New: Weather API service with caching
pages/
Weather.jsx # Updated: Now uses the service

Testing Done

  • npm run build passes successfully
  • Weather component loads and displays data correctly
  • Fresh API calls for new cities work
  • Caching works for repeat requests within 10 minutes
  • Cache expiration works after 10 minutes
  • Error handling preserved from original implementation
  • All existing functionality maintained

Before/After

Before: API calls made directly in Weather.jsx component
image

After: API calls handled by dedicated service with intelligent caching
image

Benefits

  • 🚀 Performance: Faster response for cached requests
  • 📉 Reduced API calls: Less load on wttr.in API
  • 🏗️ Better architecture: Separation of concerns (UI vs data fetching)
  • 🔧 Maintainable: Centralized weather API logic
  • User experience: Instant loading for recently searched cities

Closes #23


Note: Thank you for the opportunity to contribute to React Verse.

- Create weather service in /src/services/weather.js
- Implement in-memory caching with 10min expiration
- Extract API logic from Weather.jsx component
- Add cache management utilities
- Reduces redundant API calls and improves performance

Fixes commitra#23
@vercel
Copy link

vercel bot commented Oct 13, 2025

@aditya241104 is attempting to deploy a commit to the venisha-kalola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@venisha-kalola
Copy link
Contributor

include before and after screenshots of implementation

@aditya241104
Copy link
Contributor Author

Hi @Hrishikesh-Dalal! 👋

I've updated the PR description to include before/after screenshots

@Hrishikesh-Dalal Hrishikesh-Dalal merged commit 58acabb into commitra:main Oct 13, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weather.jsx: Extract API call into /src/services/weather.jsx and add caching

3 participants