A clean, modular, and database-driven Blog Backend built with FastAPI.
This project demonstrates real-world backend concepts like relational data modeling, API design, and database integration using SQLAlchemy.
- π€ Create Users
- βοΈ Create Blog Posts
- π One-to-Many Relationship (User β Posts)
- π Fetch All Posts
- π Fetch Posts by User
- π§ Nested API Response (User with all posts)
- π‘οΈ Input Validation using Pydantic
β οΈ Proper Error Handling (404, 400)
- β‘ FastAPI
- π Python
- ποΈ SQLite
- π§ SQLAlchemy ORM
- π¦ Pydantic
src/
βββ users/
β βββ models.py
β βββ schemas.py
β βββ controller.py
β βββ router.py
β
βββ posts/
β βββ models.py
β βββ schemas.py
β βββ controller.py
β βββ router.py
β
βββ utils/
β βββ db.py
β βββ settings.py
β
βββ main.py| Method | Endpoint | Description |
|---|---|---|
| POST | /users/create_user |
Create a new user |
| GET | /users/{user_id} |
Get user with posts |
| POST | /posts/create_post |
Create a new post |
| GET | /posts/all_posts |
Get all posts |
| GET | /posts/user/{user_id} |
Get posts by user |
{
"id": 1,
"username": "mehfooz",
"posts": [
{
"id": 1,
"title": "My First Blog",
"content": "Learning FastAPI..."
}
]
}git clone https://github.com/your-username/fastapi-blog-api.git
cd fastapi-blog-api
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn src.main:app --reloadSwagger UI available at:
π http://127.0.0.1:8000/docs
- Designing REST-like APIs
- Using SQLAlchemy ORM for database operations
- Implementing One-to-Many relationships
- Structuring scalable backend applications
- Handling real-world data flow
- JWT Authentication π
- PostgreSQL integration π
- Pagination & filtering π
- Deployment π
Built with consistency, curiosity, and discipline πͺ
More powerful systems coming soon π