This API allows you to:
- Sign up users (store in PostgreSQL table
Cplus) - Log in users
- Fetch weather forecast for a given city using OpenWeather API
Cplus_Task/
│── app/
│ │── __init__.py
│ │── database.py
│ │── main.py
│ │── models.py
│ │── schemas.py
│ │── weather.py
│── config.json
│── .env
│── requirements.txt
│── README.md
│── images/
│ │── signup-response.png
│ │── login-response.png
│ │── weather-response.png
- Python 3.9+
- PostgreSQL
- OpenWeather API key
2️⃣ Create a virtual environment
python -m venv env
source env/bin/activate # Mac/Linux
env\Scripts\activate # Windows3️⃣ Install dependencies
pip install -r requirements.txt4️⃣ Setup config.json
Edit config.json:
{
"db_user": "postgres",
"db_password": "H****d",
"db_host": "localhost",
"db_port": 5432,
"db_name": "postgres",
"weather_api_key": "***********"
}5️⃣ Optional: Set API key in .env
WEATHER_API_KEY=your_openweather_api_key
API Fetch Link: https://openweathermap.org/api
6️⃣ Create PostgreSQL database
CREATE DATABASE "postgres";7️⃣ Run the app
uvicorn app.main:app --reloadPOST /users/
{
"firstname": "Muhammad",
"lastname": "Ahmed",
"phone_number": "03348500674",
"email": "ahmed@gmail.com",
"password": "Hammad"
}curl -X 'POST' \
'http://127.0.0.1:8000/users/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"firstname": "Ali",
"lastname": "Awan",
"phone_number": "03155583363",
"email": "ali@gmail.com",
"password": "AliAwan"
}'POST /login/
{
"email": "ali@gmail.com",
"password": "AliAwan"
}curl -X 'POST' \
'http://127.0.0.1:8000/login/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"email": "ali@gmail.com",
"password": "AliAwan"
}'GET /weather/{city}
curl -X 'GET' \
'http://127.0.0.1:8000/weather/Karachi' \
-H 'accept: application/json'Once server is running:
- Visit Swagger UI: http://127.0.0.1:8000/docs
- Try endpoints directly from the browser