Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + PostgreSQL + Weather API

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

📂 Project Structure

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

⚙️ Architecture Diagram

Architecture Diagram


⚙️ Requirements

  • Python 3.9+
  • PostgreSQL
  • OpenWeather API key

📦 Installation

2️⃣ Create a virtual environment

python -m venv env
source env/bin/activate  # Mac/Linux
env\Scripts\activate     # Windows

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ 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 --reload

📄 API Endpoints


1. Sign Up

POST /users/

Request Body

{
  "firstname": "Muhammad",
  "lastname": "Ahmed",
  "phone_number": "03348500674",
  "email": "ahmed@gmail.com",
  "password": "Hammad"
}

Response Example (Image)

signup-response

cURL

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"
}'

2. Login

POST /login/

Request Body

{
  "email": "ali@gmail.com",
  "password": "AliAwan"
}

Response Example (Image)

login-response

cURL

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"
}'

3. Weather Forecast

GET /weather/{city}

Example Request

curl -X 'GET' \
  'http://127.0.0.1:8000/weather/Karachi' \
  -H 'accept: application/json'

Response Example

weather-response


Existing Responsee

table-data

🚀 Running Tests

Once server is running:


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages