Skip to content

A lightweight CMS API built with FastAPI — featuring user authentication, blog management, and like/unlike functionality. Secured with JWT, supports API versioning, and includes 100% test coverage with pytest.

Notifications You must be signed in to change notification settings

pc-crazy/fastapi-cms-api

Repository files navigation

CMS API with FastAPI

This project is a lightweight content management system (CMS) API built using FastAPI, supporting user authentication, blog creation, and like/unlike functionality.


🚀 Features

  • User Account Management: Register, login, update, delete user accounts.
  • JWT Authentication: Secure authentication using OAuth2 with JWT tokens.
  • Blog Post API: Create, retrieve, update, delete blog posts with visibility controls (public/private).
  • Like System: Users can like/unlike public or their own blog posts.
  • Access Control: Only post owners can edit/delete their posts. Private posts are only viewable by their owners.
  • SQLAlchemy (2.0 style) for efficient object relation mapping.
  • 100% Test Coverage using pytest.
  • API Versioning: Clean /v1/... structured endpoints.

📦 Technology Stack

  • Python 3.12
  • FastAPI
  • SQLAlchemy
  • JWT (PyJWT)
  • SQLite (default, can be configured for MySQL/Postgres)
  • pytest for testing

🛠 Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/pc-crazy/fastapi-cms-api.git cd fastapi-cms-api

2️⃣ Create & Activate Virtual Environment

python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate

3️⃣ Install Requirements

pip install -r requirements.txt

4️⃣ Setup Environment Variables

Create a .env file with the following content:

DB_USER=root DB_PASSWORD=yourpass DB_HOST=localhost DB_PORT=3306 DB_NAME=your_db_name SECRET_KEY=your-secret-key 

5️⃣ Run the Application

uvicorn src.main:app --reload

Visit: http://localhost:8000/docs for Swagger UI


🧪 Running Tests

pytest --cov=src tests/

You should see near 100% coverage if setup properly.


📂 Folder Structure

src/ ├── api/v1/ │ ├── accounts.py │ ├── blog.py │ └── like.py ├── auth.py ├── database.py ├── init_db.py ├── main.py ├── models.py └── schemas.py tests/ ├── test_accounts.py ├── test_blog.py ├── test_like.py ├── test_auth.py ├── test_database.py └── conftest.py 

📫 Postman Collection

A ready-to-use Postman collection is provided to test all API endpoints:

📥 Download CMS API Postman Collection

📥 Download CMS API Postman Environment

✅ The Login request includes a test script that automatically sets the access_token in the Postman environment upon successful login.

📌 Import both files into Postman. Use the environment to set base_url and access_token for authenticated requests.


🧑‍💻 Author

Developed by Paras Chauhan
GitHub | LinkedIn


📝 License

This project is open-source and available under the MIT License.

About

A lightweight CMS API built with FastAPI — featuring user authentication, blog management, and like/unlike functionality. Secured with JWT, supports API versioning, and includes 100% test coverage with pytest.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages