This repository is a hands-on learning project for building RESTful APIs using FastAPI and Flask. It explores routing, data validation, database integration with SQLAlchemy, and basic user authentication with password hashing.
blog/- Contains the FastAPI application and related files.flask_app.py- The main entry point for the Flask application.requirements.txt- Lists the dependencies for the project.blog.db- SQLite database file.
-
Clone the repository:
git clone https://github.com/your-username/mrastatine-fastapi-learning-.git cd mrastatine-fastapi-learning- -
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the FastAPI application:
uvicorn blog.main:app --reload
-
Run the Flask application:
python flask_app.py
- GET / – Home route
- GET /blog – List blogs (published/unpublished via query)
- GET /blog/{id} – Retrieve blog by ID
- POST /blog – Create a blog
- PUT /blog/{id} – Update a blog
- DELETE /blog/{id} – Delete a blog
- POST /user – Create user with password hashing
- GET / – Home route
- GET /get-user/<user_id> – Get mock user data
- POST /create-user – Create mock user from request body
- ⚡ FastAPI
- 🌐 Flask
- 🧬 SQLAlchemy (SQLite backend)
- 🛡️ Passlib + bcrypt (for password hashing)
- 📦 Pydantic (for validation)
- The FastAPI app uses a local SQLite database (
blog.db). - All blog and user data are persisted via SQLAlchemy ORM.
- Passwords are hashed before storage using bcrypt.
- Project is modular and follows basic clean code practices.