{"id":17760846,"url":"https://github.com/letsmakecakes/weather-api","last_synced_at":"2026-04-18T00:31:12.420Z","repository":{"id":258764095,"uuid":"875321363","full_name":"letsmakecakes/weather-api","owner":"letsmakecakes","description":"The Weather API Service is a Golang app that fetches real-time weather data from a third-party API, caches it using Redis, and efficiently handles requests with a 12-hour cache expiration.","archived":false,"fork":false,"pushed_at":"2024-12-05T18:22:12.000Z","size":262,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-05T20:49:32.842Z","etag":null,"topics":["api","cache","caching","go","golang","redis","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/letsmakecakes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-19T17:04:56.000Z","updated_at":"2024-12-05T18:22:16.000Z","dependencies_parsed_at":"2024-12-05T19:34:26.066Z","dependency_job_id":null,"html_url":"https://github.com/letsmakecakes/weather-api","commit_stats":null,"previous_names":["letsmakecakes/weather-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/letsmakecakes/weather-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsmakecakes%2Fweather-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsmakecakes%2Fweather-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsmakecakes%2Fweather-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsmakecakes%2Fweather-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letsmakecakes","download_url":"https://codeload.github.com/letsmakecakes/weather-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsmakecakes%2Fweather-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31951222,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cache","caching","go","golang","redis","rest-api"],"created_at":"2024-10-26T19:13:40.978Z","updated_at":"2026-04-18T00:31:12.400Z","avatar_url":"https://github.com/letsmakecakes.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Weather API Service\n\nThis project is a weather API service built using Golang. The service fetches weather data from a third-party API (e.g., Visual Crossing API) and implements caching using Redis with a 12-hour expiration. The API allows clients to retrieve current weather information for a specified city and improves performance by caching frequently requested data.\n\n## Table of Contents\n\n- [Features](#features)\n- [System Architecture](#system-architecture)\n- [Installation and Setup](#installation-and-setup)\n- [API Endpoints](#api-endpoints)\n- [API Tests](#api-tests)\n- [Usage](#usage)\n- [System Diagrams](#system-diagrams)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- Retrieves real-time weather data from a third-party API\n- Implements Redis-based caching for performance optimization\n- Custom date format handling for proper time unmarshalling\n- Graceful error handling for external API failures\n- Extensible caching layer for future optimizations\n\n## System Architecture\n\nThe system architecture is designed as follows:\n\n1. **WeatherService**:\n   - Responsible for fetching weather data from the third-party API.\n   - Implements caching using Redis to reduce API calls.\n   - Handles unmarshalling of JSON responses, including custom date formats.\n\n2. **Redis Cache**:\n   - Caches weather data for each city with a 12-hour expiration to optimize repeated requests.\n\n3. **Third-Party Weather API**:\n   - This service fetches weather data from an external API like Visual Crossing.\n\n4. **Error Handling**:\n   - If the data is unavailable or if the external API returns an error, the service will return an appropriate message.\n\n## Installation and Setup\n\n### Prerequisites\n\n- Golang (v1.18 or later)\n- Redis for caching\n- Docker (optional but recommended for running Redis and tests)\n- Visual Crossing API key (or any compatible weather API)\n\n### Step-by-Step Setup\n\n1. **Clone the Repository**:\n   ```bash\n   git clone https://github.com/your-username/weather-api.git\n   cd weather-api\n   ```\n\n2. **Set Up Environment Variables**:\n   You need to set the following environment variables for the API key and Redis connection:\n   ```bash\n   export WEATHER_API_KEY=\"your-weather-api-key\"\n   export REDIS_URL=\"redis://localhost:6379\"\n   ```\n\n3. **Install Dependencies**:\n   If you use Go modules, ensure you install all the required dependencies:\n   ```bash\n   go mod tidy\n   ```\n\n4. **Run the Service**:\n   To start the weather service, run the following command:\n   ```bash\n   go run main.go\n   ```\n\n5. **Run Redis**:\n   If you're using Docker, run Redis with:\n   ```bash\n   docker run --name redis -d -p 6379:6379 redis\n   ```\n\n## API Endpoints\n\n### `GET /weather/{city}`\n\nFetches the weather data for a specified city. If the weather data is cached, it will return the cached response, otherwise, it will fetch fresh data from the third-party API.\n\n- **URL**: `/weather/{city}`\n- **Method**: `GET`\n- **URL Params**: \n   - `city=[string]` - Name of the city\n- **Success Response**:\n  - **Code**: 200 OK\n  - **Content**: JSON containing weather data.\n  \n  Example Response:\n  ```json\n  {\n    \"queryCost\": 1,\n    \"latitude\": 37.7749,\n    \"longitude\": -122.4194,\n    \"resolvedAddress\": \"San Francisco, CA\",\n    \"days\": [\n      {\n        \"datetime\": \"2024-10-20\",\n        \"tempmax\": 21.2,\n        \"tempmin\": 13.5,\n        \"temp\": 17.8,\n        \"humidity\": 68.0,\n        \"precipprob\": 5.0\n      }\n    ]\n  }\n  ```\n  \n- **Error Response**:\n  - **Code**: 400 Bad Request\n  - **Message**: `City is required`\n  \n  - **Code**: 500 Internal Server Error\n  - **Message**: `Failed to fetch weather data`\n\n## API Tests\n\nYou can run API tests using `curl` or an API testing tool like Postman.\n\n### Example CURL Requests\n\n1. **Get Weather Data for a City**:\n   ```bash\n   curl -X GET \"http://localhost:8080/weather/London\"\n   ```\n\n2. **Handling Errors**:\n   If the city name is missing:\n   ```bash\n   curl -X GET \"http://localhost:8080/weather/\"\n   ```\n\nYou can also use Postman to simulate the requests and validate responses.\n\n## Usage\n\nOnce the service is running, you can query the weather data for a specific city by sending an HTTP `GET` request to the `/weather/{city}` endpoint. For example:\n\n```bash\ncurl http://localhost:8080/weather/London\n```\n\nThe service will first check if the data is available in the Redis cache. If not, it will fetch the data from the third-party weather API and store it in Redis with a 12-hour expiration.\n\n## System Diagrams\n![System Diagram](./system_diagram.png)\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue if you find any bugs or want to request new features.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsmakecakes%2Fweather-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletsmakecakes%2Fweather-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsmakecakes%2Fweather-api/lists"}