A powerful, async-ready 🌀 blog post API built with FastAPI, PostgreSQL, and JWT authentication. This project is designed for learning and real-world use, featuring robust testing, CI/CD integration, and modular architecture.
- ✨ Features
- ⚙️ Requirements
- 🚀 Getting Started
- ⚒️ Usage
- 📡 API Endpoints
- 🧪 Testing
- 🗂 Project Structure
- 🤝 Contributing
- 📄 License
- 🔐 JWT Authentication (OAuth2 Password Flow)
- 🧵 Fully Async with SQLAlchemy 2.0
- 🐘 PostgreSQL Database Integration
- 🧪 Pytest-based Testing Suite
- 🚦 Flake8 Linting
- 🛠 Alembic for DB Migrations
- 🔄 CI/CD with GitHub Actions
- 📦 Modular FastAPI App Structure
- ✅ Python 3.10+
- ✅ PostgreSQL
- ✅ Git
git clone https://github.com/spKnowTech/Blogpost-with-fastapi.git
cd Blogpost-with-fastapi
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Create a .env file in the root directory with the following content:
DB_HOSTNAME=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=yourpassword
DB_NAME=blogdb
TEST_DB_NAME=blogdb_test
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
ALEMBIC_DATABASE_URL=postgresql://postgres:yourpassword@localhost:5432/blogdb
alembic upgrade head
uvicorn blogpost:app --reload
- ReDoc: http://localhost:8000/redoc
| Method | Path | Description |
| ------ | -------------- | ------------------- |
| POST | `/auth/login` | Login with JWT |
| POST | `/auth/signup` | Register a new user |
| Method | Path | Description |
| ------ | ------------- | ------------------- |
| GET | `/blogs/` | List all blog posts |
| POST | `/blogs/` | Create a new post |
| GET | `/blogs/{id}` | Get a post by ID |
| PUT | `/blogs/{id}` | Update a post |
| DELETE | `/blogs/{id}` | Delete a post |
Run unit tests:
pytest tests/ -v
Lint your code:
flake8 --verbose
CI/CD will automatically:
- Spin up a PostgreSQL test container
- Run flake8
- Run all tests on every push
Blogpost-with-fastapi/
│
├── alembic/ # Alembic migration scripts
├── routers/ # API routers (auth, blogs)
├── tests/ # Unit and integration tests
├── blogpost.py # Main FastAPI app instance
├── database.py # DB engine & session
├── models.py # SQLAlchemy ORM models
├── oauth2.py # Token creation/validation
├── schemas.py # Pydantic request/response models
├── settings.py # App settings from .env
├── utils.py # Password hashing, helpers
└── requirements.txt
Contributions are welcome! 🎉
- Fork the repo
- Create a new branch
- Commit your changes
- Open a PR with a clear explanation
This project is licensed under the MIT License.
See the LICENSE file for details.
✅ Next Step: Copy this into a new file named README.md in the root of your GitHub repo.
Let me know if you want badges for test coverage, Docker instructions, or deployment tips!