Weather API Application allows users to subscribe to weather updates for their city. The API provides functionality for subscribing, confirming, unsubscribing, and retrieving weather data.
The project is deployed and available at https://weather-api-app-csei.onrender.com/.
- Weather Forecast: Get the current weather for any city.
- Subscription Management: Subscribe to receive weather updates at regular intervals (hourly or daily).
- Email Confirmation: Users must confirm their subscription via email.
- Unsubscribe: Unsubscribe from weather updates using the provided token.
- Method:
GET
- Description: Retrieve the current weather for a city.
- Query Parameters:
city
: City name (Latin letters only) for weather forecast (Required)
- Responses:
200 OK
: Successful weather retrieval400 Bad Request
: Invalid input404 Not Found
: City not found
- Method:
POST
- Description: Subscribe to weather updates.
- Form Parameters:
email
: User's email address (Required)city
: City for weather updates (Required)frequency
: Frequency of updates (hourly
ordaily
) (Required)
- Responses:
200 OK
: Subscription successful. Confirmation email sent.400 Bad Request
: Invalid input409 Conflict
: Email already subscribed
- Method:
GET
- Description: Confirm email subscription using the confirmation token sent in the email.
- Path Parameters:
token
: Confirmation token (Required)
- Responses:
200 OK
: Subscription confirmed successfully400 Bad Request
: Invalid token404 Not Found
: Token not found
- Method:
GET
- Description: Unsubscribe from weather updates using the unsubscribe token sent in the email.
- Path Parameters:
token
: Unsubscribe token (Required)
- Responses:
200 OK
: Unsubscribed successfully400 Bad Request
: Invalid token404 Not Found
: Token not found
The API documentation can be accessed through Swagger, which is available at the following URL after deployment:
Swagger URL: https://weather-api-app-csei.onrender.com/swagger
Swagger provides a complete visual representation of the API, where you can explore and test the available endpoints interactively.
- Docker
- Docker Compose
- Makefile (optional for easier management)
- Clone the repository:
git clone https://github.com/l4ndm1nes/Weather-API-Application.git
- Navigate to the project directory:
cd Weather-API-Application
cp .env.example .env
- DB_HOST: Database host (for local development, use localhost)
- DB_PORT: Database port (default: 5432)
- DB_USER: Database username (default: postgres)
- DB_PASSWORD: Database password
- DB_NAME: Database name (default: weather)
- DB_SSLMODE: Database SSL mode (for local: disable, for production: require)
- SMTP_HOST: SMTP mail host (e.g., smtp.mailtrap.io)
- SMTP_PORT: SMTP port (e.g., 2525)
- SMTP_USER: SMTP username
- SMTP_PASS: SMTP password
- SMTP_FROM: From email address
- WEATHER_API_KEY: API key for weather data
- BASE_URL: The base URL of your app (for local: http://localhost:8080, for production: your deployed URL)
docker-compose up --build
Open http://localhost:8080
in your browser to test the API.
The project includes a Makefile to simplify common tasks like building, testing, and running migrations. Here are the available commands:
make migrate-script-ready
make migrate-up
make migrate-down
make run
make build
make fmt
make lint
make test
To deploy this app to Render:
- Push your repository to GitHub.
- Go to Render.
- Create a new Web Service.
- Connect your GitHub repository.
- Set up environment variables in the Render dashboard.
- Click "Deploy" to start the deployment.
Run tests using the following command:
make test
You can also test the endpoints using curl or Postman:
curl -X GET "http://localhost:8080/api/weather?city=Kyiv"
curl -X POST "http://localhost:8080/api/subscribe" -d "email=user@example.com&city=Kyiv&frequency=daily"
curl -X GET "http://localhost:8080/api/confirm/{token}"
curl -X GET "http://localhost:8080/api/unsubsribe/{token}"
.
Weather-API-Application/
│
├── cmd/
│ └── httpserver/ - Main server entry point
│
├── docs/ - Swagger documentation
│
├── internal/ - Core application logic
│ ├── adapter/ - Adapter for interacting with repositories, external services, and APIs
│ ├── config/ - Application configuration and settings
│ ├── handler/ - API request handlers
│ ├── mocks/ - Mock objects for testing
│ ├── model/ - Data models and structures
│ ├── scheduler/ - Periodic job tasks and scheduling
│ └── service/ - Business logic services
│
├── migrations/ - Database migrations
│
├── pkg/ - Utility function packages
│ ├── middleware/ - Middleware for request processing
│
├── scripts/ - Scripts for operations, such as waiting for the database
│
├── test/ - Tests for verifying application functionality
│ ├── integration/ - Integration tests
│ └── unit/ - Unit tests
│
├── web/ - Files for the web interface
│
├── Dockerfile - Dockerfile for building the containerized application
│
├── docker-compose.yml - Docker Compose configuration for setting up the app with services
│
├── Makefile - Makefile for automation of tasks
│
├── README.md - Project documentation and setup instructions