This project is a lightweight content management system (CMS) API built using FastAPI, supporting user authentication, blog creation, and like/unlike functionality.
- 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.
- Python 3.12
- FastAPI
- SQLAlchemy
- JWT (PyJWT)
- SQLite (default, can be configured for MySQL/Postgres)
- pytest for testing
git clone https://github.com/pc-crazy/fastapi-cms-api.git cd fastapi-cms-apipython -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txtCreate 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 uvicorn src.main:app --reloadVisit: http://localhost:8000/docs for Swagger UI
pytest --cov=src tests/You should see near 100% coverage if setup properly.
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 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_tokenin the Postman environment upon successful login.📌 Import both files into Postman. Use the environment to set
base_urlandaccess_tokenfor authenticated requests.
Developed by Paras Chauhan
GitHub | LinkedIn
This project is open-source and available under the MIT License.