Skip to content

SinaGhaffarzadeh/Blogzilla

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 BlogZilla

This project is a RESTful Blog API built with FastAPI, using SQLAlchemy for ORM, SQLite as the database, and Passlib for password hashing. The API supports full CRUD operations for blogs and users and includes relationships between users and the blogs they create.

🚀 Features

  • Create, read, update, and delete (CRUD) blog posts
  • User registration with hashed passwords
  • User-to-blog relationship
  • Structured responses using Pydantic
  • Error handling with proper HTTP status codes
  • Swagger documentation (auto-generated)
  • SQLite support (ideal for testing and small-scale apps)

🏗️ Project Structure

blog/
├── __init__.py
├── main.py          # Main FastAPI application with API routes
├── models.py        # SQLAlchemy models for Blog and User
├── schemas.py       # Pydantic models for data validation and serialization
├── database.py      # DB engine, session maker, Base declaration
├── Hashing.py       # Password hashing using Passlib
├── blog.db          # SQLite database (auto-created)
├── requirements.txt # Python dependencies

📦 Requirements

Install all the dependencies:

pip install -r requirements.txt

🛠️ Setup and Run

  1. Clone the repository:
git clone https://github.com/SinaGhaffarzadeh/blogzilla
cd blogzilla
  1. Run the API using Uvicorn:
uvicorn blog.main:app --reload

Note: We use blog.main because the main.py file is located inside the blog/ folder.

  1. Access the interactive API docs:

📂 Database

This project uses SQLite as the database. Tables are automatically created when you start the server.

You can manage and visualize your SQLite database (blog.db) using TablePlus or any SQLite viewer.


🔐 Password Hashing

Passwords are securely hashed using bcrypt from Passlib:

from passlib.context import CryptContext

pwd_cxt = CryptContext(schemes=["bcrypt"], deprecated="auto")

This ensures no plain-text password is stored in the database.


📘 Endpoints Overview

Blogs

Method Endpoint Description
POST /blog Create a new blog
GET /blog Get all blogs
GET /blog/{id} Get blog by ID
PUT /blog/{id} Update a blog by ID
DELETE /blog/{id} Delete a blog by ID

Users

Method Endpoint Description
POST /user Create a new user
GET /user/{id} Get user by ID

✅ Tips & Concepts

  • HTTP Status Codes: Used extensively to provide proper feedback (e.g., 200 OK, 201 Created, 404 Not Found).
  • Response Models: Control what information is shown to users (e.g., excluding sensitive data like passwords).
  • Dependency Injection: Used to manage DB sessions via Depends(get_db).
  • Relationships: SQLAlchemy's relationship() and ForeignKey used to link users and blogs.

🔧 Future Improvements

  • JWT-based authentication & authorization
  • Pagination for blog listings
  • Update and delete operations for users
  • Unit testing and validation

About

This project is a RESTful Blog API built with FastAPI, using SQLAlchemy for ORM, SQLite as the database, and Passlib for password hashing. The API supports full CRUD operations for blogs and users and includes relationships between users and the blogs they create.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages