This project implements a simple Flask-based backend API for weather data. It allows users to retrieve weather information for specific cities, add new weather data, update existing weather data, and delete weather data for a city.
The project follows the following folder structure:
-
app.py
: The main Flask application file. It initializes the Flask app, registers routes, and starts the server. -
routes/weather_routes.py
: Defines the routes for weather data operations. -
controllers/weather_controllers.py
: Contains the controller functions for handling weather data operations. -
tests/weather_test.py
: Contains test cases to verify the functionality of the API endpoints.
-
Start the server by running the
app.py
file. -
Access the API endpoints using the following routes:
-
GET /weather-api/weather/<city>
: Retrieve weather data for a specific city. -
POST /weather-api/weather
: Add new weather data for a city. -
PUT /weather-api/weather/<city>
: Update weather data for a specific city. -
DELETE /weather-api/weather/<city>
: Delete weather data for a specific city.
Replace
<city>
with the name of the city you want to perform the operation on. -
-
Endpoint:
GET /weather-api/weather/<city>
- Description: Retrieve weather data for a specific city.
- Response: JSON object containing the weather information for the city.
-
Endpoint:
POST /weather-api/weather
- Description: Add new weather data for a city.
- Request Body: JSON object containing the city, temperature, and weather information.
- Response: JSON object containing the success message and the added weather data.
-
Endpoint:
PUT /weather-api/weather/<city>
- Description: Update weather data for a specific city.
- Request Body: JSON object containing the updated temperature and/or weather information.
- Response: JSON object containing the updated weather data.
-
Endpoint:
DELETE /weather-api/weather/<city>
- Description: Delete weather data for a specific city.
- Response: JSON object confirming the deletion of the weather data.
The project includes test cases to verify the functionality of the API endpoints. The test cases are defined in the tests/weather_test.py
file.
To run the tests, use the following command:
pytest tests/weather_test.py
Note : Make sure you have the pytest
library installed.