The Weather API hosted on AWS EC2 provides a set of endpoints for user management, weather data management, and retrieval. This API allows users to register, authenticate, save, retrieve, update, and delete weather data associated with their accounts.
Base URL: http://13.53.107.142/api/weather
Authentication for accessing protected endpoints is handled via JWT (JSON Web Tokens). Users obtain a token through the login endpoint and include it in the Authorization header for subsequent requests.
- Endpoint:
POST /user/register - Description: Registers a new user with the system.
- Request Body:
{ "username": "awsapitester", "email": "[email protected]", "password": "awsapitester1234" }
- Endpoint:
POST /user/login - Description: Authenticates a user and generates a JWT token.
- Request Body:
{ "email": "[email protected]", "password": "awsapitester1234" }
- Endpoint:
GET /user/current - Description: Retrieves details of the currently logged-in user.
- Authorization: Bearer Token required.
- Endpoint:
POST /weather/save - Description: Saves weather data for a specific location.
- Query Parameters:
email: User's email addresslocation: Location for which weather data is being saved.
- Authorization: Bearer Token required.
- Endpoint:
GET /weather/view - Description: Retrieves all saved weather data associated with the current user.
- Authorization: Bearer Token required.
- Endpoint:
PUT /weather/update-location - Description: Updates the location associated with the current user.
- Query Parameters:
newLocation: New location to update.
- Authorization: Bearer Token required.
- Endpoint:
GET /weather/retrieve - Description: Retrieves weather data for a specific date from the database.
- Query Parameters:
date: Date for which weather data is requested (e.g.,2024-07-13).
- Authorization: Bearer Token required.
- Endpoint:
GET /weather/any - Description: Retrieves weather data for any given date.
- Query Parameters:
date: Date for which weather data is requested (e.g.,2004-12-25).
- Authorization: Bearer Token required.
- Endpoint:
DELETE /weather/delete - Description: Deletes the current user and associated weather data.
- Authorization: Bearer Token required.
The app uses express-validator for request validation. Here are some validation rules applied to the endpoints:
- Email: Must be a valid email format.
- Location: Must not be empty.
- Date: Must be in ISO8601 format.
The app uses http-errors for consistent error handling. Validation errors and other exceptions are caught and handled gracefully, returning appropriate HTTP status codes and error messages.
This project is licensed under the MIT License. See the LICENSE file for more details.