Skip to content

whoismehfooz/fastapi-blog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ FastAPI Blog API

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.


⚑ Features

  • πŸ‘€ 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)

🧱 Tech Stack

  • ⚑ FastAPI
  • 🐍 Python
  • πŸ—„οΈ SQLite
  • 🧠 SQLAlchemy ORM
  • πŸ“¦ Pydantic

πŸ“‚ Project Structure

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

πŸ”₯ API Endpoints

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

πŸ§ͺ Example Response

{
  "id": 1,
  "username": "mehfooz",
  "posts": [
    {
      "id": 1,
      "title": "My First Blog",
      "content": "Learning FastAPI..."
    }
  ]
}

βš™οΈ Setup & Run

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 --reload

πŸ“– API Docs

Swagger UI available at:

πŸ‘‰ http://127.0.0.1:8000/docs


🧠 What I Learned

  • Designing REST-like APIs
  • Using SQLAlchemy ORM for database operations
  • Implementing One-to-Many relationships
  • Structuring scalable backend applications
  • Handling real-world data flow

πŸš€ Future Improvements

  • JWT Authentication πŸ”
  • PostgreSQL integration 🐘
  • Pagination & filtering πŸ“Š
  • Deployment 🌍

πŸ‘¨β€πŸ’» Author

Built with consistency, curiosity, and discipline πŸ’ͺ
More powerful systems coming soon πŸš€

About

πŸ‘‰ Blog API with FastAPI, SQLAlchemy, and relational data modeling (User ↔ Posts)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages